Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas = SliceSetting warning, whats best way to set column values?

I have, what I thought was, a simple line of code that was setting the value of a DataFrame equal to "Straddle" whenever two conditions are met:

 df['Structure'].loc[(df['Structure'] != 'Straddle') & (df['GuessVol']  > 100)] = "Straddle"

This line is throwing up a load of SettingWithCopyWarning though, and it’s driving me nuts. What would be a better way of doing this, while trying to keep it in one line of code?

Tx!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should use:

df.loc[(df['Structure']!='Straddle') & (df['GuessVol']>100), 'Structure'] = "Straddle"

to select rows and column simultaneously.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading