I have a table like:
| Month | Binary | Value_missing | Total_value |
|---|---|---|---|
| 1 | N | 40 | 120 |
| 1 | Y | 5 | 50 |
| 2 | N | 30 | 200 |
| 2 | Y | 10 | 20 |
I want to calculate in pandas a groupby that gives me a percentage of the column Value_missing based on the Total_value. I expected to get:
| Month | Binary | Value_missing | Total_value | %_Value_missing |
|---|---|---|---|---|
| 1 | N | 40 | 120 | 0,235 |
| 1 | Y | 5 | 50 | 0,029 |
| 2 | N | 30 | 200 | 0,1363 |
| 2 | Y | 10 | 20 | 0,045 |
For each row/ cell in the column Value_missing, I want to divide by the sum of Total_Value aggregated by month
An example of the calculus off the first row: 40 / (120 + 50) = 0,235
Thank you!