-1

I have the following dataframe badges from which I want to create a subset badges_gold. The condition of subset is that the UserId present in badges should be present in the list gold_users. But when I use is in operation I get invalid syntax error. How to fix this?

Main Dataframe - badges

UserId | Name
  1    | Altruist
  2    | Autobiographer
  3    | Enlightened
  4    | Citizen Patrol
  5    | python

List of Gold Badge Users - gold_users

gold_users = [1,2,3]

Code

badges_gold = badges[badges.UserId is in gold_users]

Expected Output - badges_gold

UserId | Name
  1    | Altruist
  2    | Autobiographer
  3    | Enlightened

Error

SyntaxError: invalid syntax
Ishan Dutta
  • 897
  • 4
  • 16
  • 36
  • 1
    write `in` rather than `is in` – Danis Nov 12 '20 at 06:01
  • I had tried it but using `in` gave the following error `ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().` @Danis – Ishan Dutta Nov 12 '20 at 06:02

1 Answers1

0

You'll need to make the below change and it will do the job for you.

badges[badges.UserId.isin(gold_users)]
A DUBEY
  • 806
  • 6
  • 20