0

I know they were a number of question on this warning. I read all and still could figure it out why this line gives me the warning:

This is the function I tried to call:

def createFeature(df):

    df.loc[:, 'PCT_change'] = (df.loc[:, 'Close'] - df.loc[:, 'Close'].shift(1))/df.loc[:, 'Close'].shift(1)*100.0


return df

When I called the above function with this command:

stock_train_reform = createFeature(stock_train)

The warnings appear as

stock_train_reform = createFeature(stock_train) /Applications/Spyder.app/Contents/Resources/lib/python3.5/pandas/core/indexing.py:560: 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

I don't know how to fix this warning. Please help Thanks a lot.

Rayhane Mama
  • 2,374
  • 11
  • 20
June
  • 1
  • 2
  • This seems relevant: https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas – Miriam Farber Jul 03 '17 at 22:05
  • Thank you Miriam. I found this and try to follow by using .loc but the warning is still remain. – June Jul 03 '17 at 22:13
  • Actually, I just put "df.is_copy = False" to clarify that I didn't want to copy in the "createFeature" function. It works. I hope this isn't make my result goes wrong. – June Jul 03 '17 at 22:20

0 Answers0