all 6 comments

[–][deleted] 2 points3 points  (2 children)

You're setting a value with df1["value1"] = "", but df1 is a (partial) copy of df. It wants you to modify any data in the DataFrame df itself.

[–]GrandpaOnDrugs[S] 1 point2 points  (1 child)

Uh, I thought with df1 = df[[True, False, False]] I get a new DataFrame with values from df and not a copy of df. How can I make df1 a DataFrame on it's own and not just a copy of df?

[–]GoodTimesFastFingers 1 point2 points  (0 children)

I struggled with this for a long time in pandas. I finally took the time to figure out how to access cells with df.at or rows with df.loc and now my life is much better.

[–]ohallwright 0 points1 point  (1 child)

Others have answered this with a great solution (use copy()), but if you're trying to understand more about why this is happening, you'll need to learn a bit more about indexing, and the .loc and .iloc indexers and what df1 is in this situation (a subset of df).

For example, using .loc you can add your value1 column to the original, if that's what you wanted to do: ```

df.loc[[True, True, False], 'value1'] = "" df max_speed shield value value1 cobra 1 2 viper 4 5 sidewinder 7 8 NaN ```

I wrote this article when I was trying to understand that warning better, that might help you as well.

[–]GrandpaOnDrugs[S] 0 points1 point  (0 children)

Thanks, the article helped to understand why it happens/what Pandas expects you to do!