0

When I merge two dataframes (with different number of rows) on 'Date' as below I get the Error ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat. I looked at the answer here and converted dates in both my dataframes to str but I still get the error. I tried to convert the Dates to int as well, but that results in another error ValueError: invalid literal for int() with base 10: '1919-01-01'. I'm not too sure how to solve this.

df_trial.columns =  ['Date', df_trial.columns[1]]
df_trial['Date'] = df_trial['Date'].astype(str)
df_fly.columns = ['Date', df_fly.columns[1]]
df_fly['Date'] = df_fly['Date'].astype(str)
df_trial = df_trial.merge(df_fly, left_on='Date', right_index=True).reset_index() ##Error

df_fly=
          Date       AGG
0    2003-10-01 -0.007216
1    2003-11-01 -0.000123
2    2003-12-01  0.001782
3    2004-01-01  0.009108

df_trial=
            Date   AAA
0     1919-01-01  4.09
1     1919-02-01  1.45
2     1919-03-01  5.21
Jojo
  • 1,117
  • 2
  • 15
  • 28

1 Answers1

0

This might work -

For inner join :
pd.merge(df_fly, df_trial, on='Date')

For outer join :
pd.merge(df_fly, df_trial, on='Date', how='outer')

Just ensure that the type of Date column in both dataframes is same.

Sajan
  • 1,247
  • 1
  • 5
  • 13