0
Df.loc[lambda Df: Df['score'] > 15 and Df['score'] < 20]

I am getting the mentioned error while using the above-mentioned code. Thanks in advance Error : ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
akash bais
  • 27
  • 3
  • https://stackoverflow.com/questions/21415661/logical-operators-for-boolean-indexing-in-pandas – zariiii9003 Jun 14 '20 at 15:52
  • 1
    Does this answer your question? [Logical operators for boolean indexing in Pandas](https://stackoverflow.com/questions/21415661/logical-operators-for-boolean-indexing-in-pandas) – Ken Kinder Jun 14 '20 at 15:56

1 Answers1

0

The main issue is the lack of parenthesis around the expressions.

There are two other issues in your code:

  • Use '&' instead of 'and' when working with Series.
  • No need to use lambda.

Here's a piece of code that would work:

df.loc[(df['score'] > 15) & (df['score'] < 20)]
Roy2012
  • 11,755
  • 2
  • 22
  • 35