0

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

  • 1
    There are filter, so need `df_sorted_KtoU = df_sorted[df_sorted['price'] == 'KRW/USD'].copy()` – jezrael Aug 26 '20 at 12:43
  • Wow.. Thank you very much. Then why last code is not working?? – Hyeongjin Lee Aug 26 '20 at 12:48
  • there is no loc, need `df_sorted_KtoU.loc['Rate', 'Rate : 20Day Mean'].plot(figsize = (15,8), ylim = (1000,1250))` – jezrael Aug 26 '20 at 12:49
  • Thank you for answer, but it is not working too, so I tried '''df_sorted_KtoU[['Rate', 'Rate : 20Day Mean']].plot(figsize = (15,8), ylim = (1000,1250)) ''' so it is success. I think it was not list format, so that error was happened – Hyeongjin Lee Aug 26 '20 at 12:57

0 Answers0