[英]Fastest way to count number of occurrences in Pandas
計算Pandas系列中元素出現次數的最快方法是什么?
我目前最快的解決方案是.groupby(columnname).size()
。 熊貓中有什么更快的東西嗎? 例如,我想要以下內容:
In [42]: df = DataFrame(['a', 'b', 'a'])
In [43]: df.groupby(0).size()
Out[43]:
0
a 2
b 1
dtype: int64
pandas中的value_counts()
函數完全正確。
在所需的列上使用該功能。 即
df['column_i_want'].value_counts()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.