首页 > 解决方案 > 不支持的操作数类型 python

问题描述

if((pd['data'].str.startswith('aha' | 'bou')) & (pd[‘data1’].str.startswith(‘aha’|’bou’))) 我正在使用我想从数据帧中读取的熊猫,并将以 aha 和 bou 开头的两列数据附加到列表中。在检查我得到的条件时

TypeError : 不支持的操作数类型 |: 'str' 和 'str'</p>

标签: pythonpandasstringtypeerrorunsupportedoperation

解决方案


您可以改为通过元组创建布尔掩码|,输出为布尔掩码:

m = pd['data'].str.startswith(('aha', 'bou')) & pd['data1'].str.startswith(('aha', 'bou'))

推荐阅读