2

I have a dataframe and I want to access certain entries based on particular column values. For example...the data frame has four columns 'A, B, C, D'

I want to grab a particular entry where 'A=1' and another where 'B=42'. Is there an easy way to do this?

1 Answer 1

3

This is called boolean indexing, where you slice the dataframe based on a condition:

df[df['A']==1]

or if both have to be true:

df[(df['A']==1) & (df['B']==42)]

But I recommend that you go thorugh the docs: http://pandas.pydata.org/pandas-docs/stable/10min.html, and specifically on boolean indexing: http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing

Sign up to request clarification or add additional context in comments.

Comments

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.