Harp
Harp

Reputation: 61

how to merge two dataframes according to date

I have two data frames, one looks like: enter image description here And another that looks like:

enter image description here

I'm getting an error when I try to merge the two dataframes using pd.merge The error is "value error: you are trying to merge on datetime64[ns] and int64 columns". How do I get around this problem?

Upvotes: 0

Views: 62

Answers (2)

BENY
BENY

Reputation: 323226

You can do

df['Date']=pd.to_datetime(df['Date'])
df=df.merge(df1,how='left')

Upvotes: 1

foxpal
foxpal

Reputation: 623

You'd need to have the same dtype for both columns. So convert the first date to a year, and the merge should then be fine.

df['Date'] = df['Date'].apply(lambda x: x.year)

Upvotes: 1

Related Questions