I'm using pandas 17.1. Dealing with the SettingWithCopyWarning is widely discussed on SO, but I don't believe what looks like the most popular thread addresses my use case, which is assigning a scalar to a column.
My code:
df.loc[:, "some_col_name"] = 0
Assume that the column called "some_col_name" already exists; this is not adding the column (if such a statement even could).
It's generating a SettingWithCopyWarning, and for the life of me I can't figure out why.
It works when I set df.is_copy = False first, but I'd rather avoid the extra statement every time I do this if possible.
What am I doing wrong here?
Thanks!
Follow-up response to johnchase's answer: df was created by a groupby statement (see below), so I'm not sure where I'd add in the .copy. The remedy I mentioned works, but that I have to do that means to me that pandas makes the groupby iterations not realize they're copies. (They are, though, right?)
for some_ix, df in bigger_df.groupby(cols_I_care_about):
df.loc[:, "some_col_name"] = 0