我有兩列的數據幀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