在Jupyter中无法获取'DataFrameGroupBy'对象

时间:2018-09-16 15:18:38

标签: python python-3.x dataframe jupyter-notebook pandas-groupby

我有https://www.data.gov.au/dataset/airport-traffic-data/resource/f0fbdc3d-1a82-4671-956f-7fee3bf9d7f2的这个csv文件

我正在尝试与

进行汇总
airportdata = Airports.groupby(['Year_Ended_December'])('Dom_Pax_in','Dom_Pax_Out')
airportdata.sum()

但是,我不断收到'DataFrameGroupBy'对象无法调用 它不会打印我想要的数据 如何解决该问题?

1 个答案:

答案 0 :(得分:0)

在提取列之前,您需要执行sum聚合: airportdata_agg = Airports.groupby(['Year_Ended_December']).sum()[['Dom_Pax_in','Dom_Pax_Out']] 或者,如果您想确保不汇总列,则不使用: airportdata_agg = Airports[['Dom_Pax_in','Dom_Pax_Out', 'Year_Ended_December']].groupby(['Year_Ended_December']).sum()