2

I am working with a pandas Series and I am trying to use the isin() method to find some of the members of the series. However, for pandas timestamp objects, this function does not appear to be working correctly.

import pandas

data = pandas.date_range('jan-01-2013','jan-05-2013')
s = pandas.Series(data)

print s.iloc[0] == data[0]   # Returns True (correct)
print s.isin(data[0:2])      # Returns a series of all false values (incorrect)

Obviously, for the second print statement, the expected result is that the first two members of the series are true and everything else is false. However, it returns all false values. Is this a bug or am I implementing isin() incorrectly?

tshepang
  • 12,111
  • 21
  • 91
  • 136
jsexauer
  • 681
  • 2
  • 12
  • 22
  • 1
    See the discussion [here](http://stackoverflow.com/questions/19070194/isin-function-does-not-work-for-dates); this is a bit of a headache. – DSM Oct 23 '13 at 20:17
  • @DSM thanks for link, it looks like a bug, you right. So my answer just taking out datetime64 values and isin is working, but it's not working with Timestamp :( – Roman Pekar Oct 23 '13 at 20:21
  • this will be fixed in 0.13 (coming very soon) – Jeff Oct 23 '13 at 21:58

1 Answers1

3

it's working like this:

s.isin(data[0:2].values)
Roman Pekar
  • 107,110
  • 28
  • 195
  • 197
  • 1
    N.B. as Jeff said above this is working around a bug. – Wes McKinney Oct 25 '13 at 20:54
  • @WesMcKinney I'm not at all expert in pandas, thanks for mentioning that. BTW, could you take a look at this question - http://stackoverflow.com/questions/19597575/picking-out-elements-based-on-complement-of-records-in-python-pandas? – Roman Pekar Oct 25 '13 at 21:06