d = {'a': [0,1,0,1,1,1], 'b': [1,1,1,1,1,1], 'c': [0,0,0,0,0,1], 'd': [1,0,1,1,1,0]}
dct = {'a':'top','b':'bot','c':'top','d':'bot'}
df = pd.DataFrame(d)
So I have a df and a dictionary that assigns each column to a group. Having trouble creating a function that creates a total(sum) column for the group. This would be the output of the first 2 rows:
| a | b | c | d | total_top | total_bot |
|---|---|---|---|---|---|
| 0 | 1 | 0 | 1 | 0 | 2 |
| 1 | 1 | 0 | 0 | 1 | 1 |
and so on.... Ideally taking the dataframe and name of the group as inputs