现在,我有这个系列:
0 a,b
1 a
2 c
3 b,a,d
4 a,c
dtype: object
所以,我怎样才能像这样获得系列(我尝试使用 sr.value_counts(),但无效):
a 4
b 2
c 2
d 1
dtype: int64
谢谢
最佳答案
您可以拆分和扩展字符串,例如:
>>> sr.str.split(',', expand=True).stack().value_counts()
a 4
b 2
c 2
d 1
dtype: int64
关于python - 我如何通过 Pandas 获得号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45829534/