Klausos Klausos
Klausos Klausos

Reputation: 16050

How to filter out rows based on specific column values

I have a pandas data frame. I need to select Score for those entries that have column's Ind values equal to 0.

Score = df[df['Ind'] == 0]['Score']

How can I do this?

Upvotes: 1

Views: 358

Answers (1)

EdChum
EdChum

Reputation: 394031

Use loc:

Score = df.loc[df['Ind']==0, 'Score']

So we pass the boolean condition as the first param and then col of interest.

The boolean condition generates a boolean mask that is used to mask the index against so will only return those rows.

The docs give various examples of indexing

Upvotes: 1

Related Questions