我有两列的数据帧df
一列,它的列是phone
和label
,其label
只能是0或1。
下面是一个例子:熊猫数据帧更新使用另一种柱
phone label
a 0
b 1
a 1
a 0
c 0
b 0
我想要做的是计算每种类型的'电话'的'1'的数量,并使用数字替换'电话'列 我附带的是groupby
,但我不熟悉它
T他的回答应该是:
Count the number of each 'phone'
phone count
a 1
b 1
c 0
replace the 'phone' with 'count' in the original table
phone
1
1
1
1
0
1
你想找到没有。 'phone'中的行给出了标签== 1? –
你想要:'df.groupby ['phone']。sum()'? – bernie
但我怎样才能取代'电话'与'总和' – Fan