为什么Dataframe.groupby.sum()不显示汇总值?

时间:2019-05-21 16:37:53

标签: python pandas

import pandas as pd
import numpy as np

data_agency = pd.read_excel("Sample.xlsm")

enter image description here

data_agency.groupby(['Person']).sum()

但是我得到的东西类似于仅一行的数据: enter image description here

type(data_agency['Person'].iloc[0])返回str类型

type(data_agency['Reg Hrs.'].iloc[0])返回float64类型

2 个答案:

答案 0 :(得分:0)

您可以选择那些列,然后应用聚合

data_agency.groupby(['Person'])[["LunchBreak", "HoursWorked", "Regofhours","RegNSDHrs","RegOTNSDHRS"]].sum()

答案 1 :(得分:0)

data_agency.groupby('Person').agg('sum')