0

I want to index a DataFrame using Boolean values, for example:

x = pd.DataFrame((100,2), columns = ("a", "b"))
s = x.b > 0

How to choose rows where s is true?

2 Answers 2

1

Try this:

mask = x.b > 0
subset = x[mask]
Sign up to request clarification or add additional context in comments.

Comments

0
 bool_value=x['b']>0
 required_rows=x[bool_value]

 # one line code
 required_rows=x[(x['b']>0)]

1 Comment

Please add some explanation with your answer so that others can learn as well.

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.