>>> df.groupby(['year', 'Tm'], as_index=False).count()
year Tm a
0 2014 ATL 4
1 2014 BOS 4
2 2014 BRK 1
3 2014 CHI 1
4 2014 CHO 1
5 2014 CLE 1
6 2014 DAL 1
7 2014 DEN 1
8 2014 DET 1
9 2014 GSW 1
对于大小:
Another simple aggregation example is to compute the size of each group. This is included in GroupBy as the size method. It returns a Series whose index are the group names and whose values are the sizes of each group.
在groupby语句中指定
as_index=False
。作为补充说明,您可能希望使用count(不包括nan)而不是size。你知道吗对于大小:
对于计数:
我想您可以用参数} 作为新列名
name
尝试^{Size
:样品:
不带参数
name
获取新列0
:相关问题 更多 >
编程相关推荐