Generation

generate functionSat, 25 Feb 2023

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 column names and rate_group are row names. Inside the rows should be the sum of the id by grouping grades and rate_group.

import pandas as pd def group(df): df = df.pivot_table(index='rate_group', columns='grade', values='id', aggfunc=np.sum) return df

Questions about programming?Chat with your personal AI assistant