I have a pandas dataframe with three columns: Close, Open and Target. The "Target" column is supposed to equal (Close - Open)/Open. But the following line generates a "SettingWithCopyWarning", which is hard to understand, because this expression would not generate a problem with numpy arrays. The line that generates the warning is this:
df["Target"] = (df["Close"] - df["Open"])/df["Open"]
And the warning message is hard to understand. Here is the warning message:
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
How to modify the original code to make the warning go away?