0

I'm doing a somewhat complex lookup of dates in multiple tables. I've run into this error a bunch and have previously found what was wrong and fixed it.

Here, I'm puzzled. I like to oversimplify the issue so I can figure it out. The following has me scratching my head:

print ('04/01/2009' in trouble_df['Date'])
>False

OK, so the index isn't in the list I'm looking at. So I pulled up this list, and found the value '04/01/2009', along with its index. So I tried:

print (trouble_df['Date'][157])
>04/01/2009

Maybe the date is the wrong datatype.

print (type(trouble_df['Date'][157]))
> <class 'str'>

Nope. OK, how is this possible:

print (trouble_df['Date'][157] in trouble_df['Date'])
>False

Please help!

David William
  • 65
  • 2
  • 9
  • Try also printing its `len`. There might be *SPACE*s (or other "hidden" chars) at the end. Regarding the last part, I have 0 *Pandas* knowledge, but if a dataframe works like a `dict` then the last `print` is fine, you might have wanted to type `if 157 in trouble_df['Date'])`. – CristiFati Jan 12 '18 at 19:25
  • Also, is this python 3 or 2? `str` in python 3 is Unicode, which opens up a host of potential causes – kdopen Jan 12 '18 at 19:26
  • If you want to search through the Series, you should use `trouble_df['Date'][157] in trouble_df['Date'].values`. Otherwise it searches the index. – ayhan Jan 12 '18 at 19:30

1 Answers1

0

in is work for list in pandas it is isin

df=pd.DataFrame({'id':['01/01/2018','01/02/2018']})
df.id.isin(['01/01/2018']).any()
Out[659]: True
'01/01/2018' in df.id.tolist()
Out[660]: True
BENY
  • 317,841
  • 20
  • 164
  • 234