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

Time:07-12

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!

CodePudding user response:

You should use:

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

to select rows and column simultaneously.

  • Related