In my dataframe I want to sum certain rows in a column and output them in a new column ‘UE_more_days’
is
ATEXT BEGUZ_UE UE_more_days
0 11.00 0.0
1 CT 23.00 Nan
2 RT 33.00 46.0
3 15.00 0.0
3 15.00 0.0
4 12.75 0.0
5 19.75 0.0
6 14.75 0.0
7 CT 23.00 29.5
8 CT 24.00 46.0
9 CT 24.00 48.0
10 RT 33.00 48.0
11 15.00 0.0
12
etc
should be
ATEXT BEGUZ_UE UE_more_days
0
1 CT 23.00
2 RT 33.00 56.0
3 15.00
4 12.75
5 19.75
6 14.75
7 CT 23.00
8 CT 24.00
9 CT 24.00
10 RT 33.00 104.0
11 15.00
12
etc
my last try
bedd2 = [(df['ATEXT'] != ''),]
result2 = [(df.iloc[0:]['BEGUZ_UE'].astype(float).reset_index(drop=True) +
df.iloc[1:]['BEGUZ_UE'].astype(float)).round(decimals=2).shift(1)]
df['min_UE_mehr_Tage'] = np.select(bedd2, result2)
How can I sum rows from a column based on a condition and output them in a new column?
New contributor
user25786233 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1