python实现excel 的lookup函数

sx_customer_0409=pd.read_excel(r'E:\lll\\sx_customer_0409.xlsx')#读取数据
fx_variable=pd.read_excel(r'E:\lll\202004\\fx_variable.xlsx')#读取分箱列表

'''定义lookup函数'''
def lookup(lookup_value,lookup_vector,return_vector):
    """
    与Excel中的lookup函数一样
    """
    return return_vector[lookup_value >= lookup_vector].tolist()[-1]

'''遍历数据表的变量执行lookup函数'''
for i in variable:
    sx_customer[i] = sx_customer[i].apply(lookup,args=(fx_variable[fx_variable['变量']==i]['下限'],fx_variable[fx_variable['变量']==i]['分值']))#args给自定义函数第一参数以为的参数赋值

你可能感兴趣的:(python,学习)