I got a DatFrame looking like this:
ID field_1 area_1 field_2 area_2 field_3 area_3 field_4 area_4
1 scoccer 500 basketball 200 swimming 100 basketball 50
2 volleyball 100 np.nan np.nan np.nan np.nan np.nan np.nan
3 basketball 1000 football 10 np.nan np.nan np.nan np.nan
4 swimming 280 swimming 200 basketball 320 np.nan np.nan
5 volleyball 110 football 160 volleyball 30 np.nan np.nan
The original DataFrame has the same structure but containing columns field_1 up to field_30 as well as area_1 to area_30.
I'd like to add columns to the DF with horiztonal groups depending on the distinct expressions in 'field_x' with the correspondig area summed up... the added columns should look like this:
ID group_1 area_1 group_2 area_2 group_3 area_3
1 scoccer 500 basketball 250 swimming 100
2 volleyball 100
3 basketball 1000 football 10
4 swimming 480 basketball 320
5 volleyball 140 football 160
Is there an easy way to realize this?