Below for you to share a pandas multilevel grouping implementation of the method of sorting, with a good reference value, I hope to be helpful to everyone. Come and see it together.
Pandas have groupby grouping functions and sort_values sort functions, but how do you sort the dataframe after grouping them?
in []: DF = PD. DataFrame ((Random.randint), Random.choice ([' Tech ', ' art ', ' Office '), '%dk-%dk '% (Random.randint (2,10), Random.randint (+)), ') for _ in Xrange (10000)), columns=[' publish_time ', ' classf ', ' salary ', ' title ']) in []: df.he AD () out[71]: publish_time CLASSF salary Title0 the art 2k-19k1 Office 5K-17K2 Office 2K-10K3 Art 5k-14k4 art 2k-14kin [the]: Df.groupby ([' Publish_time ', ' classf ', ' salary ']). Count () [' Title '].groupby (Level=0, Group_keys=false). Nlargest (Ten) out[72]:p ublish_time classf salary2012 Art 7k-13k 4k-13k Tech 3k-12k art 6k-16k 8k-15k Office 5k-18k Tech 4k-14k 13