2018-12-18
阅读量:
844
pandas如何将数据聚合?
Groupby方法(聚合):
groupby方法允许我们根据任何行或列将数据组合在一起,因此我们可以进一步应用聚合函数来分析我们的数据。使用mapper(dict或key函数,将给定函数应用于组,将结果作为系列返回)或通过一系列列的组系列。
考虑这是由以下代码生成的DataFrame:
import pandas as pd
import numpy as np
# create DataFrame
dframe = pd.DataFrame({'Geeks': [23, 24, 22, 22, 23, 24],
'For': [10, 12, 13, 14, 15, 16],
'geeks': [122, 142, 112, 122, 114, 112]},
columns = ['Geeks', 'For', 'geeks'])
# Apply groupby and aggregate function
# max to find max value of column
# "For" and column "geeks" for every
# different value of column "Geeks".
print(dframe.groupby(['Geeks']).max())






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论