我正在尝试在 Python 中创建一个函数,该函数接受未指定数量的条件以在内部使用mask
fromdfply
以过滤掉匹配的行。
from dfply import *
def select_filters(df, *condition):
return df >> mask(condition)
然后我想在这个例子中使用两个过滤器来做这样的事情:
select_filters(df, (X.col1 <= 15) | (X.col2 > 10))
目前,我能够运行以下内容:
def select_filters2(df, col, num):
return df >> mask(X[col] <= num)
select_filters2('col1', 15)
但是,select_filters2
我想要的非常有限:您只能使用一个过滤器(一列)并且不能更改不等式。如何捕捉这一切?