swas
swas

Reputation: 79

Python filter dataframe with condition and column

i'm curious if it's possible to filter a pandas DataFrame by column and a condition. Or do i have to do it with two steps.

So my basic idea is to do:

 df['cluster' & (df['Type'] == 't')]

Or is there no overhead achieving this by two steps like:

tmp = df[df['Type'] == 't']
tmp = tmp[df['Type']]

Upvotes: 2

Views: 284

Answers (1)

Oriol Mirosa
Oriol Mirosa

Reputation: 2826

You can do:

df.loc[df['Type'] == 't', 'cluster']

Upvotes: 2

Related Questions