1

This question has been posted in a few forms, but for some reason, none of the solutions are working for my use case. I have a lookup number that is part of a class that I have created. I want to simply see if that number exists in a column of my dataframe. Below are the solutions I've tried :

 # Where body_part.LookupNumber is a unique int and body_part.SymptomTable['BodyPartIllnessTypeId'] is a column of ints. 
 if body_part.LookupNumber in body_part.SymptomTable['BodyPartIllnessTypeId'].tolist():
      do something 
 
 # Get this error ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() 

 # Fair enough, so then I tried this: 
 if body_part.LookupNumber in body_part.SymptomTable['BodyPartIllnessTypeId'].values:
     do something
 # Get this error ValueError: Lengths must match to compare

Oddly enough, when I run this, it prints. In this case I've instantiated i to be a class object:

if i.LookupNumber in i.SymptomTable['BodyPartIllnessTypeId'].values:
 print('worked')

Thanks for your time.

romeo
  • 35
  • 4
  • 1
    Are you certain that `body_part.LookupNumber` is really an integer? please print the `type()` of each element in the first if statement. Also I believe that the [`.isin()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.isin.html) function of pandas series will be helpful here. Best of luck. – Yonlif Oct 04 '20 at 18:20
  • 1
    Does this answer your question? [How to determine whether a Pandas Column contains a particular value](https://stackoverflow.com/questions/21319929/how-to-determine-whether-a-pandas-column-contains-a-particular-value) – woblob Oct 04 '20 at 18:24

1 Answers1

1

Big thanks to @Yonlif. It was a bad mistake on my part. The type of body_part.LookupNumber was in fact not an int.

romeo
  • 35
  • 4