DOC: CoW and column addition
Pandas version checks
- [X] I have checked that the issue still exists on the latest versions of the docs on
mainhere
Location of the documentation
https://pandas.pydata.org/docs/getting_started/intro_tutorials/05_add_columns.html
Documentation problem
I’m still grasping at the CoW error message and how to replace the usefull df['newcolumn'] = process(df['existing_column']), as the error message sends to a not so usefull help page (See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy, may need a separate ticket, but a simple example using a single index would definitely have helped me. The MultiIndex example clearly hides the message behind unnecessary complexity).
But the above mentioned help page (https://pandas.pydata.org/docs/getting_started/intro_tutorials/05_add_columns.html) does not seem to follow the "new good practices" and should probably be updated.
Suggested fix for documentation
I’m not used enough to the new "standard", but the:
air_quality["london_mg_per_cubic"] = air_quality["station_london"] * 1.882
should probably resemble something like:
air_quality[:, "london_mg_per_cubic"] = air_quality["station_london"] * 1.882
and the same for the second example.
I believe df['newcolumn'] = process(df['existing_column']) should create a new column on df with CoW enabled, can you provide a reproducible example?
A likely point of confusion: df[mask]['newcolumn'] = some_value will not update df because df[mask] is a copy of df, and df[mask] will get updated instead (and then immediately garbage collected).
I am very confused by this, we need 2 things here:
- The warning message that Gets raised (the complete message)
- A complete reproducer, the thing you wrote up should be completely valid, that's why we need something that we can run
Closing for now. @JB-AM - if you can provide a reproducible example, happy to reopen! Just comment here.