我不明白为什么发生SettingWithCopyWarning

问题描述

我试图将函数滚动到提取的数据帧。

df = pd.read_csv('ExchangeRate_2020-08-24.csv',index_col = 'Date',parse_dates = True)
df_sorted = df.sort_values(by=['Date'])
df_sorted_KtoU = df_sorted[df_sorted['price'] == 'KRW/USD']
df_sorted_UtoE = df_sorted[df_sorted['price'] == 'USD/EUR']
df_sorted_KtoU['Rate : 20day Mean'] = df_sorted_KtoU['Rate'].rolling(window=20,min_periods = 1).mean()
df_sorted_KtoU.head()

我可以得到正确的答案,但这是警告,


C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ ipykernel_launcher.py:4:SettingWithcopyWarning: 试图在DataFrame的切片副本上设置一个值。 尝试改用.loc [row_indexer,col_indexer] = value

请参阅文档中的警告:http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy 从sys.path中删除cwd之后。


我如何编写更好的代码

Futhermore,

df_sorted_KtoU['Rate','Rate : 20day Mean'].plot(figsize = (15,8),ylim = (1000,1250))

它根本无法正常工作

请帮助我

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)