This is my data frame:
df =
GROUP GRADE TOTAL_SERVICE_TIME TOTAL_WAIT_TIME
AAA 1 45 20
AAA 4 40 23
AAA 5 35 21
BBB 2 30 24
BBB 3 55 22
I want to group the records GROUand GRADE, estimate the average value TOTAL_SERVICE_TIMEand mean TOTAL_WAIT_TIMEfor each group, as well as count the number of records that belong to each group.
I do not know how to do the counting:
output = df.groupby(['GROUP','GRADE'])
.agg({'TOTAL_SERVICE_TIME' : 'mean', 'TOTAL_WAIT_TIME' : 'mean'})
.value_counts()
.reset_index()
I also tried adding , 'COUNT' : 'count', but the column COUNTshould already exist.
source
share