The method of pandas multilevel grouping to realize sorting

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.