The GroupBy of Python

Source: Internet
Author: User

#-*-Coding:utf-8-*-
"""
Created on Sat June 30 10:09:47 2018
Test group GroupBy
@author: Zhen
"""
From pandas import DataFrame
"""
data = [
[1,2,2,1]
[2,2,2,2]
[1,3,3,2]
[2,2,2,4]
]
"""
# Create test data, convert dictionary into data frame
DF = DataFrame ({' A ': [1,2,2,1], ' B ': [2,2,2,2], ' C ': [1,3,3,2], ' d ': [2,2,1,4]})

Show2 = Df.groupby ([' A ', ' B ', ' C ']) [' C '].agg ([' Max ', ' min ', ' mean '])
SHOW3 = Df.groupby ([' B ', ' A ', ' C ']) [' C '].agg ([' Max ', ' min ', ' mean '])

Print (' ===================================== ')
Print (DF)
Print (' ===================================== ')
Print (SHOW2)
Print (' ===================================== ')
Print (SHOW3)
Print (' ===================================== ')

Results:

Analysis:

according to the analysis of the results: groupby in Python is similar to SQL, and the order of grouped columns affects the hierarchical relationship of results, but does not affect the results!

The GroupBy of Python

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.