与此:
df = pd.DataFrame({'players.name': ['John', 'Will' ,'John', 'Jim', 'Tim', 'John', 'Will', 'Tim'],
'players.diff': [0,0, 0, 0, 0, 0, 0, 0]})
但是'players.name'值重复了很多次,我需要计算每个唯一名称出现的次数os,并添加带有该值的列'count',最后是:
players.name players.diff counts
0 John 0 3
1 Will 0 2
2 John 0 0
3 Jim 0 1
4 Tim 0 2
5 John 0 0
6 Will 0 2
7 Tim 0 2
我该怎么做?