因此,我正在运行此代码,以根据其他列中的条件添加新列。
conditions = [
(df['PMA'] == 'EEA') & (75 > df['AR'] >= 55) & (70 > df['RR'] >= 55) & (df['SR'] <= 75) & (df['RMA'] <= 130),
(df['PMA'] == 'EEA') & (df['AR'] >= 75) & (df['RR'] >= 70) & (df['SR'] <= 75) & (df['RMA'] <= 130),
(df['PMA'] == 'EMERGING') & (70 > df['AR'] >= 50) & (60 > df['RR'] >= 50) & (df['SR'] <= 75) & (df['RMA'] <= 130),
(df['PMA'] == 'EMERGING') & (df['AR'] >= 70) & (df['RR'] >= 60) & (df['SR'] <= 75) & (df['RMA'] <= 130)
]
choices = ['PSS Eligible', 'SSDI Eligible', 'PSS Eligible', 'SSDI Eligible']
df['Eligibility'] = np.select(conditions, choices, default='Not Eligible')
我得到了:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
知道它从哪里来吗?
编辑:
根据您的建议,我将其更改为:
conditions = [
(df['PMA'] == 'EEA') & (df['AR'] < 75) & (df['AR'] >= 55) & (df['RR'] < 70) & (df['RR'] >= 55) & (df['SR'] <= 75) & (df['RMA'] <= 130),
(df['PMA'] == 'EEA') & (df['AR'] >= 75) & (df['RR'] >= 70) & (df['SR'] <= 75) & (df['RMA'] <= 130),
(df['PMA'] == 'EMERGING') & (df['AR'] < 70) & (df['AR'] >= 50) & (df['RR'] < 60) & (df['RR'] >= 50) & (df['SR'] <= 75) & (df['RMA'] <= 130),
(df['PMA'] == 'EMERGING') & (df['AR'] >= 70) & (df['RR'] >= 60) & (df['SR'] <= 75) & (df['RMA'] <= 130)
]
choices = ['PSS Eligible', 'SSDI Eligible', 'PSS Eligible', 'SSDI Eligible']
df['Eligibility'] = np.select(conditions, choices, default='Not Eligible')
现在可以使用!谢谢!