<分区>
我尝试了以下代码将列转换为“日期”:
df.['DATE'] = pd.to_datetime(df['DATE'])
或
df.DATE = pd.to_datetime(df.DATE)
但我收到以下错误:
/Users/xyz/anaconda3/envs/sensor/lib/python3.6/site-packages/pandas/core/indexing.py:517: 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
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self.obj[item] = s
我将代码更改为以下内容:
df.loc[:,'DATE'] = pd.to_datetime(df.loc[:,'DATE'])
但我仍然得到同样的错误。
同理
for i in df.index:
df.loc[i,'DATE'] = pd.to_datetime(df.loc[i,'DATE'])