Home > OS >  np. where : compare the absolute value of a column
np. where : compare the absolute value of a column

Time:09-20

I am using np.where to calculate the amount of a column but need to analyse only abolute values without chaning a column itself. Currently, I am using this code:`

dfv['Movement'] = np.where(dfv['Variance vs last December'].gt(2000000), 'Y','N')

Is there any way to include absolute in here?

Kind Regards

CodePudding user response:

try this:

dfv['Movement'] = np.where(abs(dfv['Variance vs last December']).gt(2000000), 'Y','N')

CodePudding user response:

Use Series.abs:

dfv['Movement'] = np.where(dfv['Variance vs last December'].abs().gt(2000000), 'Y','N')
  • Related