我试图根据列值列表筛选数据帧的行。问题是,我有动态输入的列的长度,到目前为止,我已经尝试过了,但这并不能达到我的目的。在
>>>df
a b
0 jdfb sdvkb
如果我必须同时搜索这两列。也就是说,如果a='jdfb'
和{
我将动态创建的搜索列存储在列表变量fields
中,值也存储在另一个列表变量“matchlist”中。在
方法1我尝试了这个方法,它奏效了:
>>> df[fields].isin(matchlist)
a b
0 True True
这很好。这正是我想要的。但当我尝试下一个查询时,这不是我想要的,因为它不应该起作用:
>>> df[fields].isin(matchlist)
a b
0 True True
这种方法的问题是列应该按照方法1中指定的顺序匹配,而不是按照我尝试的下一种方式。我有什么办法可以做到这一点吗?在
生成两个独立的布尔索引并将它们组合起来可能更容易。在
相关问题 更多 >
编程相关推荐