我正在尝试在pandas中应用一个函数,这需要我使用额外的变量来评分。例如:
def get_score_threshold(pred_df):
score_thresholds = {}
score_thresholds['a_thresh'] = np.percentile(pred_df['pred'],75)
score_thresholds['b_thresh'] = np.percentile(pred_df['pred'],50)
score_thresholds['c_thresh'] = np.percentile(pred_df['pred'],25)
return score_thresholds
def score_pred(pred,scores):
if pred >= scores['a_thresh']:
return 'A'
elif pred >= scores['b_thresh']:
return 'B'
elif pred >= scores['c_thresh']:
return 'C'
else: return 'D'
close_preds['score'] = close_preds['pred'].apply(score_pred(scores=close_pred_thresh))
如何指定第一个变量是传递的行,第二个变量是我提供的附加参数?
答案 0 :(得分:1)
来自the documentation,它似乎是
close_preds['score'] = close_preds['pred'].apply(score_pred, args=(pred, scores))
我无法看到你close_pred_thresh
的内容。 score_pred
需要两个参数。