I keep getting the warning in the subject in the following situations:
Step 1:
df.rename(columns={'one':'one_a'}, inplace=True)
Step 2:
df.drop(['one', 'two', 'three'], axis=1, inplace=True)
How do I fix?
I had a similar problem and to fix I did the following:
new_df = df.copy()
new_df.rename(columns={'one':'one_a'}, inplace=True)
new_df.drop(['one', 'two', 'three'], axis=1, inplace=True)
Or you can do
df.is_copy = False
You were probably using a copy of your original DF (ex: you were manipulating your DF before that) and that's why you were receiving the warning. More on copy:
why should I make a copy of a data frame in pandas
Easiest fix (and probably good programming practice) would be to not do inplace operations, e.g.
df2 = df.rename(columns={'one':'one_a'})
One way around it is to remove inplace=True, then use:
df = df.drop(['one', 'two', 'three'], axis=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With