0

I have this code snippet but i got warning. How can avoid this. I search this problem but couldnt find any to solve mine.

And here is the code that gets warning, (df_test_arima is pandas dataframe)

df_test_arima['ACTUAL'] = y_test

y_test is from ;

X_train,X_test,y_train,y_test = train_test_split(X.index,y, shuffle = False, test_size=0.050)

Warning that i got

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

Thank you :)

Sevval Kahraman
  • 1,185
  • 3
  • 10
  • 37
  • Does this answer your question? [How to deal with SettingWithCopyWarning in Pandas](https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas) – Anurag Dabas May 20 '21 at 14:36
  • How can i use this? I saw this question. Same warning but not the use of code. – Sevval Kahraman May 20 '21 at 14:38

1 Answers1

1

Try loc (to copy all corresponding rows, cols)

df_test_arima['ACTUAL'] = y_test.loc[:,:]

Another way is to disable all such warning in your file (not recommended though)

import warnings
warnings.filterwarnings("ignore", category=SettingWithCopyWarning)
Pawan Jain
  • 815
  • 3
  • 15