There is a Pandas dataframe: id grade rate_group 0 1077501 B 10-11% 1 1077430 C 15-17% 2 1077175 C 15-17% 3 1076863 C 13-14% 4 1075358 B 12-13% 5 1075269 A 7-8% 6 1069639 C 15-17% 7 1072053 E 17-25% 8 1071795 F 17-25% 9 1071570 B 12-13% Modify the dataframe so that grades are in columns and rate_group in rows.
df = pd.DataFrame({'grade': ['A','B','C','D','E','F'], 'rate_group': ['7-8%', '10-11%', '12-13%', '15-17%', '17-25%', '17-25%', '17-25%'], 'id': [1077501, 1077430, 1077175, 1076863, 1075358, 1075269, 1069639, 1072053, 1071795, 1071570]}) df.set_index(['id', 'rate_group'], inplace=True) df.unstack(level='rate_group')