I have a pandas dataframe with a range of columns, including column "A" I want to add 3 new columns to it, and this method works:
for sample in samples:
df= df1.loc[df1['sample'] == sample, ]
df.reset_index(inplace=True, drop=True)
df["new"] = df["A"].diff()
df["new2"] = df["new"].diff()
df["new3"] = np.nan
However all of these operations give the following warning:
SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
What is the right way of assigning the new columns without the warning? I've had a look at How to deal with SettingWithCopyWarning in Pandas? but I don't understand what the issue is.
Thanks