Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I am trying to modify a DataFrame df to only contain rows for which the values in the column closing_price are between 99 and 101 and trying to do this with the code below.

However, I get the error

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

and I am wondering if there is a way to do this without using loops.

df = df[(99 <= df['closing_price'] <= 101)]

1 Answer

0 votes
by (41.4k points)

You should use () to group your boolean vector to remove ambiguity.

For grouping boolean vector to remove ambiguity you should use :

df = df[(df['closing_price'] >= 99) & (df['closing_price'] <= 101)]

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...