You are trying to merge on datetime64[ns] and object columns. If you wish to proceed you should use pd.concat
时间: 2024-05-05 15:22:33 浏览: 277
It seems like you're trying to merge two dataframes on columns with different data types. One column is datetime64[ns] and the other is object. To proceed with the merge, you can use the `pd.concat()` function. Here's an example:
``` python
import pandas as pd
df1 = pd.DataFrame({'date': ['2021-01-01', '2021-01-02', '2021-01-03'], 'value': [1, 2, 3]})
df2 = pd.DataFrame({'date': pd.to_datetime(['2021-01-01', '2021-01-02', '2021-01-03']), 'comment': ['good', 'better', 'best']})
merged_df = pd.concat([df1, df2], axis=1)
print(merged_df)
```
Output:
```
date value date comment
0 2021-01-01 1 2021-01-01 good
1 2021-01-02 2 2021-01-02 better
2 2021-01-03 3 2021-01-03 best
```
In this example, `df1` has a column named `date` with object data type, and `df2` has a column named `date` with datetime64[ns] data type. We use `pd.to_datetime()` to convert the `date` column in `df2` to datetime64[ns] data type, and then use `pd.concat()` to merge the two dataframes on the common column `date`.
阅读全文