I have a DataFrame that looks like this:
I need to calculate the percentage based on the count
column which I already did following this answer.
The result is this:
Now I need to add the results for the Groupby column back into the original DataFrame. I tried grouped.reset_index()
and then adding it but I get an error ValueError: cannot insert count, already exists
since the column used in the Group by is also used in the aggregation.
Can anyone help me to find a way to add the results back to the DataFrame?