我不明白为什么发生SettingWithCopyWarning

时间:2020-08-26 12:41:34

标签: python pandas indexing chained

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

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

它根本无法正常工作

请帮助我

0 个答案:

没有答案
相关问题