Solved : You are trying to merge on object and datetime64[ns] columns

Johan Louwers
2 min readMar 22, 2021
Python Pandas

Trying to merge two Python Pandas dataframes resulted in an error stating that the merg on an object column and a datetime column was not allowed. Which is all honesty is making sense.

The error shown when trying to run the code is shown below;

ValueError: You are trying to merge on object and datetime64[ns] columns. If you wish to proceed you should use pd.concat

To find out the Dtype of the fields I tried to merge on you can use the .info option in the form of df.info() .For the dataframe data the result of data.info() was the below where you can see the Dtype of ds is object

# Column Non-Null Count Dtype 
— — — — — — — — — — — — — — —
0 ds 1429 non-null object
1 y 1429 non-null float64

If we do the same for the prediction dataframe with a prediction.info() we get the following and see that the Dtype for ds is datetime64[ns]

# Column Non-Null Count Dtype 
— — — — — — — — — — — — — — —
0 ds 1457 non-null datetime64[ns]
1 trend 1457 non-null float64
2 yhat_lower 1457 non-null float64
3 yhat_upper 1457 non-null float64
4 trend_lower 1457 non-null float64
5 trend_upper 1457 non-null float64
6 additive_terms 1457 non-null float64
7 additive_terms_lower 1457 non-null float64
8…

--

--

Johan Louwers

Johan Louwers is a technology enthousiasts with a long background in supporting enterprises and startups alike as CTO, Chief Enterprise Architect and developer.