计算ID的数量-Python

时间:2018-07-17 16:45:58

标签: python count

我希望计算ID出现在python中新列中的次数

基本上,它将R中的这段代码翻译成python

library(dplyr)
ren2 <- ren2 %>% group_by(ID) %>% mutate(count=n())

谢谢

1 个答案:

答案 0 :(得分:0)

尝试一下:

df['count'] = df.groupby('ID').transform('count')