python - 不支持的操作数类型 python
问题描述
if((pd['data'].str.startswith('aha' | 'bou')) & (pd[‘data1’].str.startswith(‘aha’|’bou’)))
我正在使用我想从数据帧中读取的熊猫,并将以 aha 和 bou 开头的两列数据附加到列表中。在检查我得到的条件时
TypeError : 不支持的操作数类型 |: 'str' 和 'str'</p>
解决方案
您可以改为通过元组创建布尔掩码|
,输出为布尔掩码:
m = pd['data'].str.startswith(('aha', 'bou')) & pd['data1'].str.startswith(('aha', 'bou'))
推荐阅读
- python - zip输出中的值数量不正确?
- elixir - 如何在同一范围内配置实时仪表板和 JSON API?
- mysql - MySQL将触发器从更新转换为插入
- reactjs - 如何使用 d3-scale 时间获取两个日期之间的日期
- sql-server - SSIS2017 项目不从环境中获取参数
- python - MultiIndexing pandas 数据框,带有用于箱线图的加载文件名前缀
- python - RPi.GPIO 中断然后让调用者立即返回?
- powershell - 如何在 powershell 中验证 IIS web.config
- r - 使用 ggtree 时,“错误:必须从色调调色板中请求至少一种颜色”
- python - Python - 将两个 Pandas 数据帧合并为一个,如果索引存在则更新该行,如果不存在则添加一行