python - Multiindex assigning while avoiding SettingWithCopyWarning -


this code works, generates settingwithcopywarning. since warning can useful, i'd rather not turn off globally. in other cases i've found ways achieve same result, without triggering warning, can't think of alternative here:

# df not yet have colz # df indexed date , name (which not use here) df["colz"] = 0.0 z = df.xs(mydate, level="date", drop_level=false)["colz"] z[:36] = 99.0 df.loc[(mydate,), ("colz",)] = z 

i can't take cross section (xs) , assign new column, because cross section give me copy. , can't take cross section cells want set 99, because need slice index , row, need blend of iloc , loc. 1 possibility reset index drop name level , put again afterward, seems yucky.

any suggestions, or live warning?

you can disable warning following code:

with pd.option_context('mode.chained_assignment',none):     code here 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -