0

I have the following dataframe:

import pandas as pd

df = pd.DataFrame()
df["L1"] = ["A", "A", "B", "B"]
df["L2"] = [0, 1, 0, 1]
df["V1"] = [1,2,3,4]
df["V2"] = [4,3,2,1]
df = df.set_index(["L1", "L2"])
df

And I'm doing the following operation which raises the warning:

temp = df.loc[("A", slice(None)), :]
temp.loc[:, "V1"] /= 3 # warning

Then I'm using

df.loc[("A", slice(None)), :] = temp
df

and it works fine. How can I avoid the warning from the first operation?

Berkos
  • 13
  • 3
  • Your reproducible code doesn't trigger the warning. It might be due to something else that you were doing previously. In doubt, just use `.copy()` on your input to ensure having a copy. – mozway May 02 '23 at 09:51

0 Answers0