如何将运算符作为参数传递给函数,并在该函数内部使用该运算符来选择 pandas 行?
# helper.py
def get_milage(operator, condition):
return df[df.Milage <operator> condition]
# main.py
import operator
get_milage(operator.lt, 7)
最佳答案
我认为需要使用operator
在 ()
中,与 operator.lt(column, value)
相同的是:
# helper.py
def get_milage(operator, condition):
return df[operator(df.Milage, condition)]
关于python - Pandas:如何应用传递的条件运算符来选择 pandas 中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49556145/