1

I am trying to create a new df with certain columns from 2 others:
The first called visas_df:
enter image description here

And the second called cpdf:
enter image description here

I only need the highlighted columns. But when I try this:

df_joined = pd.merge(cpdf,visas_df["visas"],on="date")

The error appearing is: KeyError: 'date'

I imagine this is due to how I created cpdf. It was a "bad dataset' so I did some fidgeting.Line 12 on the code snipped below might have something to do, but I am clueless...
enter image description here

I even renamed the date columns of both dfs as "date and checked that dtypes and number of rows are the same.

Any feedback would be much appreciated. Thanks!

1 Answer 1

1

df['visas'] in merge function is not a dataframe and its not contain date column. İf you want to df as a dataframe, you have to use double square bracket [[]] like this:

df_joined = pd.merge(cpdf,visas_df[["date","visas"]],on="date")
Sign up to request clarification or add additional context in comments.

Comments

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.