pandas - How to create new column with positive instead negativ values -



pandas - How to create new column with positive instead negativ values -

okay, have pandas dateframe shown beneath.

date time value/mwh 01.08.2009 00:00 - 01:00 0 01.08.2009 01:00 - 02:00 -100 01.08.2009 02:00 - 03:00 80 01.08.2009 03:00 - 04:00 50

if there value < 0, wanted have value positive value in new column. if es case, in left columns shoult 0.

it have this:

date time value/mwh 01.08.2009 00:00 - 01:00 0 0 01.08.2009 01:00 - 02:00 0 100 01.08.2009 02:00 - 03:00 80 0 01.08.2009 03:00 - 04:00 50 0

how can this?

this works me:

df['new'] = 0 df.new.loc[df['value/mwh']<0] = df['value/mwh'].abs() df['value/mwh'].loc[df['value/mwh']<0] = 0

you should avoid utilize unusual column names, can generate errors.

pandas

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -