1

Why does the following fail with KeyError 'NUM'?

result = pandas.merge(sdf_subset, dfgeom, how='inner', on=['ID', 'NUM'])

The column 'ID' exists in sdf_subset and 'NUM' exists in dfgeom. I have checked the datatype and both are Int64.

Any ideas?

1
  • check if the column names have spaces, what does sdf_subset.columns.tolist() and dfgeom.columns.tolist() show? Commented May 23, 2017 at 11:17

1 Answer 1

5
# you need to use left_on and right_on if the joining key is different between the dataframes.
result = pandas.merge(sdf_subset, dfgeom, how='inner', left_on='ID', right_on='NUM')
Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome. Please accept the answer if it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.