0

Taking inspiration from the data here we have the following Series/Dataframe

df = data.groupby(["Manufacturer","Product Name","Product Launch Data"]).sum("total")

                                                 total
Manufacturer Product Name Product Launch Date       
Apple        iPad         2010-04-03              30
             iPod         2001-10-23              34
Samsung      Galaxy       2009-04-27              24
             Galaxy Tab   2010-09-02              22

How do we sort after total while still keeping the groups i.e ending up with:

                                                 total
Manufacturer Product Name Product Launch Date       
Apple        iPad         2010-04-03              30
             iPod         2001-10-23              34
Samsung      Galaxy Tab   2010-09-02              22
             Galaxy       2009-04-27              24

1 Answer 1

2

In last pandas versions is possible sorting by levels and columns names together, so here working:

df = df.sort_values(['Manufacturer','total'])
print (df)
                                               total
Manufacturer Product Name Product Launch Date       
Apple        iPad         2010-04-03              30
             iPod         2001-10-23              34
Samsung      Galaxy Tab   2010-09-02              22
             Galaxy       2009-04-27              24
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! How come I have not seen that - I have been starring at the documentation for so long now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.