2

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']]
0

1 Answer 1

2

You can do:

df.loc[df['Type'] == 't', 'cluster']
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, this is exactly what OP need :)
If add some data sample solution will be better :)
Ah thank you very much. I somehow couldn't find this way to filter the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.