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
Post a Comment