I'm having throuble working with the isin method when working with pandas indexes, it always returns False.
from pandas import DataFrame
df = DataFrame(data=[['a', 1], ['b', 2], ['c', 3]], index=['N01', 'N02', 'N03'])
df.index.isin(['01', '02'])
returns
array([False, False, False], dtype=bool)
Use str.contains
and pass a regex pattern:
In[5]: df.index.str.contains('01|02')
Out[5]: array([ True, True, False], dtype=bool)
isin
looks for exact matches which is why you get all False
array returned
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With