Following advice I received on StackOverflow, I thought I had solved my `CopyWithWarning problems when using Pandas dataframes, but they are back to bite me. I'm trying to create a new column in a dataframe that is the first difference of another column:
df[upper_sys_hrt] = df[idx_upper] - df[idx_upper].shift(1)
df[upper_sys_hrt].iloc[0] = d[upper_sys_hrt].iloc[1]
This sometimes (not always) gives me a CopyWithWarning
error. I tried changing this to
df[ : , df.get_loc(upper_sys_hrt)] = df[ : , df.columns.get_loc(idx_upper)] - df[: , df.columns.get_loc(idx_upper)].shift(1)
but all i get is an error message:
TypeError: '(slice(1, None, None), 3)' is an invalid key
I have tried (hunt and peck) changes to the syntax as well as Googling and gotten nowhere. What am I doing wrong?