I have this pandas
DataFrame
val
datetime attribute_id
2018-01-31 0 4.162565
1 3.305480
2 3.191123
3 3.601398
4 3.277375
6 3.556552
2018-02-28 0 0.593762
1 0.594565
2 0.583355
3 0.611113
4 0.577600
6 0.638904
And I would like to have a column ratio
where for each month each attribute is divided by the mean of all other attributes.
For example, for datetime
= 2018-01-31, which refers to the month of January, I would like the column ratio
to contain the value of attribute 0 (4.162565) divided by the mean of attributes 1,2,3,4 and 6 which is the mean of 3.305480, 3.191123, 3.601398, 3.277375 and 3.556552. This month-wise for each attribute.
datetime
and attribute_id
are a MultiIndex
.
Does someone know how to do this?