如果我对您的理解正确,则可以使用pandas.Series.value_counts。
例:
import pandas as pdimport numpy as nps = pd.Series(['Katherine', 'Robert', 'Anne', np.nan, 'Susan', 'other'])s.value_counts()Katherine 1Robert 1other 1Anne 1Susan 1dtype: int64
您提供的数据只有每个名称之一-因此,这里是带有多个“凯瑟琳”条目的示例:
s = pd.Series(['Katherine','Katherine','Katherine','Katherine', 'Robert', 'Anne', np.nan, 'Susan', 'other'])s.value_counts()Katherine 4Robert 1other 1Anne 1Susan 1dtype: int64
应用于数据 框后, 您将按以下方式调用此方法:
df['names'].value_counts()


![熊猫列中唯一值的计数[重复] 熊猫列中唯一值的计数[重复]](http://www.mshxw.com/aiimages/31/637097.png)
