'Setting with copy warning with .cumsum [duplicate]

I am trying to add a new column to my pandas dataframe called cumulative cases and have tried using

df.loc[:,"cumulative cases"] = df["Cases"].cumsum()

this gives me the warning

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

self.obj[key] = value

I don't understand what I have to do to remove this warning, the output is what I wanted even with this warning



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source