0

I have the following dataframe:

df = pd.DataFrame({'Name':['Tony','Mathew'],'Value':['1','2']})

How do I check if 'Tony' exists in column 'Name'? I tried the following, but it doesnt seem to work:

print(bool('Tony' in df.Name))  

Which is always returning False despite 'Tony' being present in column 'Name'

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Tony Mathew
  • 880
  • 1
  • 12
  • 35
  • @yatu the question you marked is not a duplicate. The question you tagged has a list, which compares itself with a particular column in dataframe and again return a Series with values True/False. What I want is to find if a string is present or not in a particular column – Tony Mathew Jun 01 '19 at 17:20
  • `df.Name.isin(['Tony'])`. Or in your case if you want to use `in`, `'Tony' in df.Name.values.tolist()`. Doesnt work with pdSeries directly – yatu Jun 01 '19 at 17:21
  • @yatu, ''Tony' in df.Name.values.tolist()' This is what I wanted, thanks :) – Tony Mathew Jun 01 '19 at 17:22

0 Answers0