具有两个数据框列作为参数的Lambda

时间:2019-12-13 18:16:02

标签: python pandas lambda

我正在尝试使用lambda函数更新数据框中的新列。 lambda函数将使用其他两个现有列作为参数。尝试此操作时出现错误。该错误表明缺少一个参数,但我相信我正在传递Y参数。

def rule_greater_than(col, weight_col, weight, threshold):
    if col >= threshold:
        weight_col = weight
        else:
        weight_col = 0
    return weight_col  

def resumeJobDescriptionSimilarity_rule(df, weight, threshold):
    df['resumeJobDescriptionSimilarity_rule'] = None
    df['resumeJobDescriptionSimilarity_rule'] = df[['resumeJobDescriptionSimilarity',
                                                   'resumeJobDescriptionSimilarity_rule']].apply(lambda x, y: rule_greater_than(x, y, weight,
                                                                                                                               threshold))
    return df

resumeJobDescriptionSimilarity_rule(x, 0.5, 0.03)
x


TypeError: ("<lambda>() missing 1 required positional argument: 'y'", 'occurred at index resumeJobDescriptionSimilarity')

0 个答案:

没有答案