I need some help with a pandas issue.
So I have the next dataframe:
Timestamp group total_per_group
2018-01-01 1 5
2018-01-01 0 1
2018-02-01 0 7
2018-03-01 1 0
2018-03-01 0 4
2018-04-01 1 2
2018-04-01 0 1
2018-05-01 1 4
2018-06-01 1 5
2018-06-01 0 2
In which the column total_per_group
indicates the total puntuation for either group 1 or group 0 in the month indicated by timestamp (there can be only one group in a given timestamp, check for example, 2018-02-01, in which we only have group 0).
I want to add a new column called total
in which i have the total punctuation earned by the two groups in a month given by timestamp.
It would look like the following:
Timestamp group total_per_group total
2018-01-01 1 5 6
2018-01-01 0 1 6
2018-02-01 0 7 7
2018-03-01 1 0 4
2018-03-01 0 4 4
2018-04-01 1 2 3
2018-04-01 0 1 3
2018-05-01 1 4 4
2018-06-01 1 5 7
2018-06-01 0 2 7
I've tried to do a groupby using the timestamp column, but the problem is that I want to add the column to the original dataframe, and it gives me an output with 6 rows (one per timestamp).
Any help on this issue would be great.
Thank you very much in advance!