Background
I have a dataframe with multiple columns. I am trying to sum all the E and B values into a single column
t_start t_end B1 E1 B2 E2
1/11/2021 0:00 1/11/2021 0:05 0 2.03 0 9.01
1/11/2021 0:00 1/11/2021 0:05 0 2.03 0 9.01
1/11/2021 0:00 1/11/2021 0:05 0 2.03 0 9.01
Problem
Thing is, the file might have 10+ E and B columns, (B1, B2, B3, etc).
What I've tried
I've tried the below, but it errors out if the columns don't exist
df['sum_b'] = df['b1'] + df['b2'] + df['b3'] ...
I've also tried using a group by solution which I saw here, but it doesn't work either, as it drops off my date columns
def left(s, amount):
return s[:amount]
df.T.groupby([left(s, 1) for s in df.T.index.values]).sum().T)
Help Requested
If anyone knows how to make a dynamic sum formula which will add b and e columns, it would be much appreciated!