我如何从group by中获得第一列?蟒蛇熊猫

时间:2018-07-10 11:31:27

标签: python arrays pandas-groupby

这是代码。

import pandas as pd
df = pd.DataFrame({'Age':[0,0,1,14,15,30,31,50,51,79,78,45,22,15,80]})
print(df['Age']) 
a=df.groupby(['Age']).size()

print(a)

输出:

Age
0     2
1     1
14    1
15    2
22    1
30    1
31    1
45    1
50    1
51    1
78    1
79    1
80    1
dtype: int64

我想将年龄作为第一列,将大小作为第二列放入数组。 我该怎么办?

0 个答案:

没有答案