计数没有。数据框中的特定值 pandas

Count no. of specific values in a dataframe pandas

我是数据分析方面的新手。我正在尝试使用 python 分析数据集。

  1. 我要数数。幸存列中的 1s
  2. 没有。性别列中的男性、女性

PassengerId Survived Pclass Sex<br> 0 1 0 3 男性 1 2 1 1 女性 2 3 1 3 男性 3 4 1 1 女性 4 5 0 3 男性

我尝试了 groupby() 但它给出了错误。

In[88] titanic_data.groupby('Survived') Out[88] <pandas.core.groupby.DataFrameGroupBy object at 0x000000000BFFE588>

请提出解决方案

使用value_counts:

df['Survived'].value_counts()
df['Sex'].value_counts()