错误 "Can only use .dt accessor with datetimelike values"

error "Can only use .dt accessor with datetimelike values"

我怎么能告诉我我必须改变什么我在我的视图 django 中添加这部分时出现错误

 new = output_df.groupby([output_df['Date and Time'].dt.date, 'PCR POS/Neg']).size().unstack(fill_value=0)
        new.sort_values(by=['Date and Time'], ascending=True)
        new['Total per date'] = output_df.groupby([output_df['Date and Time'].dt.date])['PCR POS/Neg'].count()
        new.loc['Total', :] = new.sum(axis=0)

似乎“日期和时间”不是具有日期时间格式的列。您可以尝试在该行之前用此转换该列:

output_df['Date and Time'] = pd.to_datetime(output_df['Date and Time'])