我嘗試下面的代碼轉換列 「日期」:熊貓:SettingWithCopyWarning:
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'])
之前的代碼是什麼? – jezrael
'df = data.loc [data.ID == 79]' – athraa