I can't understand why SettingWithCopyWarning is happened

19 Views Asked by At

I tried to rolling function to dataframe extracted.

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

I can get a right answer but it's warning,


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:4: 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/user_guide/indexing.html#returning-a-view-versus-a-copy after removing the cwd from sys.path.


How can I code better?

Futhermore,

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

it is not working at all T.T

Please help me

0

There are 0 best solutions below