Pandas.Index.isin()因大数据集而失败

时间:2017-08-25 19:11:25

标签: pandas debugging dataframe indexing

这是一个例子

创建一个包含100M相同行的表:

>>> df = pd.DataFrame([('20170101', 'TULIP', 'FLOWER')] * 100000000, columns = ['DATE', 'NAME', 'TYPE'])

将前2列设为索引:

>>> df.set_index(['DATE', 'NAME'], inplace=True)

然后检查索引是否在[('20170101', 'TULIP')]中,对于所有行都应该为真:

>>> df.index.isin([('20170101', 'TULIP')])
array([False, False, False, ..., False, False, False], dtype=bool)

所以Pandas给出的结果是错误的 - 它的全部都是False。实际上,如果我只检查前1M行,它会给出正确的结果:

>>> df[:1000000].index.isin([('20170101', 'TULIP')])
array([ True,  True,  True, ...,  True,  True,  True], dtype=bool)

这是熊猫的错误​​吗?或者我错过了什么?

1 个答案:

答案 0 :(得分:0)

Per @Jeff在对OP的评论中,这个问题将在版本0.21中修复。