您好,我有以下数据框。 Group Size Short Small Short Small Moderate Medium Moderate Small Tall Large我想计算同一行出现在数据框中的次数。 Group Size Time Short Small 2 Moderate Medium 1 Moderate Small 1 Tall Large 1
2 回答
达令说
TA贡献1821条经验 获得超6个赞
您可以使用groupby的size:
In [11]: df.groupby(["Group", "Size"]).size()
Out[11]:
Group Size
Moderate Medium 1
Small 1
Short Small 2
Tall Large 1
dtype: int64
In [12]: df.groupby(["Group", "Size"]).size().reset_index(name="Time")
Out[12]:
Group Size Time
0 Moderate Medium 1
1 Moderate Small 1
2 Short Small 2
3 Tall Large 1
添加回答
举报
0/150
提交
取消