ValueError: You are trying to merge on datetime64[ns] and object columns. If you wish to proceed you should use pd.concat
这一般是合并的不同的dataframe中columns的数据类型(on="keys")不一致造成的。
检查办法:print (df.dtypes)
解决办法:类型转换。
1. 先存为csv, 再重新导入。
2. 类型转换:
df['keys'] = df['keys'].apply(int) index.index = pd.to_datetime(index.index, format="%Y-%m-%d") # convert the 'Date' column to datetime format df['Date']= pd.to_datetime(df['Date']) # Check the format of 'Date' column df.info() # convert the 'Date' column to datetime format df['Date'] = df['Date'].astype('datetime64[ns]') # Check the format of 'Date' column df.info()
Index.astype
Index.astype(dtype, copy=True)
参数
dtype : numpy dtype or pandas type
copy : bool, default True
其他转换方法
to_numeric() (conversion to numeric dtypes)
to_datetime() (conversion to datetime objects)
to_timedelta() (conversion to timedelta objects)