如何检查相同值 pandas 的一列中存在多少行?

How do I check how many rows exists in one column of the same value pandas?

我有一个包含大约 20 万篇文章的 pandas 数据集,其中包含一个名为“类别”的列。如何显示所有不同类型的文章并计算特定类别(例如“娱乐”)在“类别”列中的行数?

使用Series.value_counts, then is possible see unique Category values in index and for count select values by Series.loc:

s = df['Category'].value_counts()

print (s.index.tolist())

print (s.loc['Entertainment'])

要得到不同的 Category :

df['Category'].unique()

以及以下使用 contains 计算类别 Entertainment 的行数:

len(df[df['Category'].str.contains('Entertainment')])