python - pandas isin 需要可散列的数据?
问题描述
该pandas.Series.isin
函数是否要求数据是可散列的?我在文档中没有找到这个要求(Series.isin或Series,尽管我看到索引需要是可散列的,而不是数据)。
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))
这是故意的吗?它是否记录在某处?或者它是熊猫的一个错误?
解决方案
推荐阅读
- xml - 使用 xsl 检查 XML 字符串中的值
- apache - mod_rewrite,重定向并设置cookie,防止重定向循环
- django - DetailSerializer 具有 listerializer 属性
- python-3.x - 用于创建文件夹的 Python API 并在文件夹已存在时附加增量编号
- powershell - 我可以优化这个 PowerShell 解析器吗
- codeblocks - 代码块上的“collect2:错误:ld 返回 1 个退出状态”(Raspberry Pi 3b/GCC 5.4.0)
- voronoi - 加权功率 voronoi - power_diagramer.exe 文件
- wso2 - 是否可以通过 DSS payloadFactory+Call 在 Enterprise Integrator 中使用事务中介?
- tensorflow - 语义图像分割 NN (DeepLabV3+) 的内存过多问题
- python - Numpy:从一个numpy数组中减去1到每个元素