0

Hi I want to filter a large dataframe based on if a columns row is in a list object.

I tried the code below but i get an error:

df[df['castaway_id'] in [1,2,3,4]]

enter image description here

Is there an alternative to this or another way to do the same

Cha
  • 35
  • 6

1 Answers1

1

Yes, the usual way is to use the isin method as below :

df[df['castaway_id'].isin([1,2,3,4])]
Lucas
  • 36
  • 1
  • 2
  • Thanks ! that helped . do you know if it is even possible to use the in operator in this case – Cha Apr 21 '23 at 22:19
  • Glad I cloud help. You can mark the answer as the correct one. To answer your other question, no because it will compare the entire column with an element of the list. – Lucas Apr 22 '23 at 00:55