filter dataframe value in pandas

Question:

Hi I was trying to extract only the no’s from a columns in my df with this code:

(df['hello']=='No')

But it changes the values from the df and put it like a boolean values, I just want to value_count in that column the No’s, but I’m not sure what I’m doing wrong.

enter image description here

Asked By: Eduardomaker

||

Answers:

Assume you are using pandas.DataFrame, if you want to get the subset of df rows with 'hello' column value 'No', use:

df[df['hello']=='No']

If you only want the column 'hello':

df['hello'][df['hello']=='No']
Answered By: Ligon Liu

If you would like count

(df['hello']=='No').sum()

More like value_counts

df['hello'].value_counts().loc['No']
Answered By: BENY

You can actually query a DataFrame with .value_counts(). This will return an integer of how many times the query is True.

print(df['hello'].value_counts()['No'])
Answered By: David Moruzzi
print(df['hello'].value_counts())
Answered By: Lowin Li
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.