df.groupby('Agent Shift').agg({'CSAT Score': ['count','sum','mean']}).sort_values(ascending=False)
Output
TypeError: DataFrame.sort_values() missing 1 required positional argument: ‘by’
Then I add Agent Shift in sort_values
`df.groupby(‘Agent Shift’).agg({‘CSAT Score’: [‘count’,’sum’,’mean’]}).sort_values(by=[Agent Shift],ascending=False)
Output
CSAT Score
count sum mean
Agent Shift
Split 3648 16151 4.427357
Night 1316 5644 4.288754
Morning 41426 173554 4.189495
Evening 33677 144015 4.276361
Afternoon 5840 25067 4.292295
When I am trying to sort by count, sum or mean I get error
`df.groupby(‘Agent Shift’).agg({‘CSAT Score’: [‘count’,’sum’,’mean’]}).sort_values(by=[count],ascending=False)
Output
‘count’
When I am trying to sort by the CSAT Score it gives this error as well
df.groupby(‘Agent Shift’).agg({‘CSAT Score’: [‘count’,’sum’,’mean’]}).sort_values(by=[‘CSAT Score’],ascending=False)
Output
ValueError: The column label ‘CSAT Score’ is not unique.
For a multi-index, the label must be a tuple with elements corresponding to each level.
I dont know how to fix so it sorts by the aggregate functions. Any help is appreciate!
This is the output I expect
df.groupby('Agent Shift')['CSAT Score'].count().sort_values(ascending=False)
Output Agent Shift Morning 41426 Evening 33677 Afternoon 5840 Split 3648 Night 1316
I am able to sort it separately, but I want to be able to for all agg in one sit
Luis Prieto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.