Premium problem149. Cross-Tabulation as Row Percentages

Medium Locked

survey has columns gender and purchased.

Return the same contingency table as the counts version, but with each row scaled to percentages summing to 100, rounded to 2 decimal places.

The normalisation is over rows, not the whole table, so each gender's row sums to 100 regardless of how many people are in it.

Input

  gender purchased
0      f       yes
1      f        no
2      m       yes
3      m       yes
4      m        no
5      f       yes

Output

purchased     no    yes
gender                 
f          33.33  66.67
m          33.33  66.67

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)