1. Dataframe分组用groupby("列名")或者groupby(["列名1","列名2"])

import pandas as pd
df = pd.DataFrame({'性别' : ['', '', '', '',
                            '', '', '', ''],
                   '成绩' : ['优秀', '优秀', '及格', '',
                            '及格', '及格', '优秀', ''],
                   '年龄' : [15,14,15,12,13,14,15,16]})
df

Series和Dataframe分组时使用groupby函数的区别

count=df.groupby(["性别","年龄"]).count()
count

Series和Dataframe分组时使用groupby函数的区别

count=df.groupby("性别").count()
count

Series和Dataframe分组时使用groupby函数的区别

 

 2. Series分组用groupby(Series)

import pandas as pd
ds = pd.Series({'小明' : '', '小张' : '', '小赵' : ''})
GroupBy=ds.groupby(ds)
GroupBy.describe()

Series和Dataframe分组时使用groupby函数的区别

 

 

 

相关文章:

  • 1970-01-01
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-12-10
  • 2021-12-08
  • 2021-09-17
猜你喜欢
  • 2021-04-28
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案