熊猫指数是方法

Geo*_*rge 4 python indexing pandas

在使用pandas索引时,我正在使用isin方法,它总是返回False.

from pandas import DataFrame
df = DataFrame(data=[['a', 1], ['b', 2], ['c', 3]], index=['N01', 'N02', 'N03'])
df.index.isin(['01', '02'])
Run Code Online (Sandbox Code Playgroud)

回报

array([False, False, False], dtype=bool)
Run Code Online (Sandbox Code Playgroud)

EdC*_*ica 5

使用str.contains并传递正则表达式模式:

In[5]: df.index.str.contains('01|02')

Out[5]: array([ True,  True, False], dtype=bool)
Run Code Online (Sandbox Code Playgroud)

isin查找完全匹配,这就是为什么你False返回所有数组