gpt4 book ai didi

python - Pandas :SettingWithCopyWarning:

转载 作者:太空狗 更新时间:2023-10-30 02:39:09 29 4
gpt4 key购买 nike

<分区>

我尝试了以下代码将列转换为“日期”:

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'])

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com