首页 > 解决方案 > pandas isin 需要可散列的数据?

问题描述

pandas.Series.isin函数是否要求数据是可散列的?我在文档中没有找到这个要求(Series.isinSeries,尽管我看到索引需要是可散列的,而不是数据)。

foo = ['x', 'y']
bar = pd.Series(foo, index=['a', 'b'])
baz = pd.Series([foo[0]], index=['c'])
print(bar.isin(baz))

按预期工作并返回

a     True
b    False
dtype: bool

但是,以下失败并出现错误TypeError: unhashable type: 'list'

foo = [['x', 'y'], ['z', 't']]
bar = pd.Series(foo, index=['a', 'b'])
baz = pd.Series([foo[0]], index=['c'])
print(bar.isin(baz))

这是故意的吗?它是否记录在某处?或者它是熊猫的一个错误?

标签: pythonpandastypeerror

解决方案


推荐阅读