I got a dataframe like the below:
| DATETIME STR | VALUE |
|------------------|-------|
| 23/04/2019 05:00 | 500 |
| 23/04/2019 05:00 | 300 |
| 23/04/2019 05:00 | 150 |
| ................ | ... |
| 23/04/2019 23:55 | ... |
I want to go through the dataframe once and add a new column that has the percentage of each cell of the total one. The total one is different for different times.
For example the above percentages for the 23/04/2019 05:00 would be:
| DATETIME STR | VALUE | PERCENTAGE |
|------------------|-------|------------|
| 23/04/2019 05:00 | 500 | 52.63 % |
| 23/04/2019 05:00 | 300 | 31.58 % |
| 23/04/2019 05:00 | 150 | 15.79 % |
| 23/04/2019 10:00 | 600 | ..... % |
| ................ | ... | ..... % |
| 23/04/2019 23:55 | ... | ..... % |
How can I do this?
I think I am looking at something like:
dataframe["PERCENTAGE"] = (100 * dataframe["VALUE"])/sum_of_same_date
I can't figure how to calculate the sum_of_same_date
for each cell that is getting filled at the same time that I am going through the dataframe filling the new column.
Any help would be appreciated.