python - Pandas 多个过滤器 str.contains 或不包含
问题描述
我需要在表的 2 列结构上构建多个过滤器是 7 列,但第一个“查询”和最后一个“模板”正在过滤
我之前做过,但现在(1年后)我不知道出了什么问题。
for item in glob.glob('D:\\path\\*.change'):
table = pd.read_csv(item, sep='\t', index_col=None)
#FILTERING
filtered_table = table[
(table['query'].str.contains("egg*", regex=True)==False) &
(table['query'].str.contains(".*phospho*", regex=True)==False) &
(table['query'].str.contains("vipe", regex=True)==False) &
(table['template'].str.contains("ABC1")) |
(table['template'].str.contains("bender")) ]
预期结果是没有包含字符串的行的表 - egg*, 。“查询”列中的phospho , vipe 和“模板”列中包含“ABC1”或“bender”的行。
解决方案
我对问题的回答:
for item in glob.glob('D:\\path\\*.change'):
table = pd.read_csv(item, sep='\t', index_col=None)
#FILTERING
query_table = table[
(table['query'].str.contains("egg*", regex=True)==False) &
(table['query'].str.contains(".*phospho*", regex=True)==False) &
(table['query'].str.contains("vipe", regex=True)==False) ]
filtered_table = query_table[
(query_table['template'].str.contains("ABC1")) |
(query_table['template'].str.contains("bender")) ]
推荐阅读
- python-3.x - 打包 Pythons 虚拟环境以使用单个 .exe 进行分发
- javascript - 我的代码在未来的操作中没有价值
- amazon-web-services - 在 Cloud Trail 上检测到存储桶的 S3 存储桶策略不正确
- django - Django 教程第 3 部分 - 错误的链接或目录结构
- c# - 检索在 page_load 中加载的列表值
- python - 如何继续在后台运行 python 脚本
- c# - 将平面查询变成二维表
- google-apps-script - 无法获取最新数据
- vue.js - 如何在 vue 方法中弹出剑道对话框
- python - 如何将其放入 Python 中的数据框中?