首页 > 解决方案 > 在 Pandas 中进行日期时间对话时获取“SettingWithCopyWarning”

问题描述

我正在尝试将日期时间字段转换为熊猫中的日期。

我的代码

final_result['DATE_TO'] = pd.to_datetime(final_result['DATE_TO'], utc=True, dayfirst=True).dt.date

来自 Python 的警告消息

/opt/app-root/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

样本数据

final_result['DATE_TO_']
0      2020-01-26 10:07:02
1      2019-11-27 06:12:12
2      2019-12-11 08:00:08
3      2019-12-05 11:20:03
4      2019-12-07 04:50:10

如何解决这个问题。

标签: pythonpandasdataframedatetime

解决方案


推荐阅读