0

I have downloaded some data from yahoo finance, but the displayed date is out by one day IE the last row of the data frame has the date of 11/19 when it should 11/20. Even though I have a dirty fix for this that seems to work, I keep getting this error and it concerns me

:2: 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: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

The DF is called S1 and the line of code I am trying to use is this

S1['NewDate'] = S1['Date'] + pd.Timedelta(days=1)

Is this error a problem? Should I ignore it or is there a way to write it to eliminate the error?

Ben
  • 25
  • 2
  • At some point _before_ this provided code you have unsafely subset your DataFrame. Either `S1 = df[cols]` or `S1 = df[mask]` when it should have been `S1 = df[cols].copy()` or `S1 = df[mask].copy()` The warning is letting you know that `df[mask]['col'] = value` may not work because `df[mask]` may produce a copy and recommends that you use `df.loc[mask, 'col'] = value` but that message is not helpful here. – Henry Ecker Nov 20 '21 at 04:32

1 Answers1

0

This should remove the warning

S1 = S1.assign(NewDate=S1['Date']+pd.Timedelta(days=1))
Anurag Dhadse
  • 1,722
  • 1
  • 13
  • 26