np. where : compare the absolute value of a column

Viewed 29

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

2 Answers

try this:

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

Use Series.abs:

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