我无法将 Pandas 数据框类型转换为日期时间

I can't convert the Pandas Dataframe type to datetime

我很确定我应该这样做:

df['date'] = pd.to_datetime(df['date'])

但是不断出现错误:"KeyError: 'date'" 数据框如下所示:

         date       value
0  2004-01-01       0.265
1  2004-01-02       0.440
2  2004-01-05      -0.955
3  2004-01-06      -1.892

我找到问题了。当您将 .csv 保存为 CSV UTF-8 格式时会出现问题。