【发布时间】:2021-06-26 16:45:39
【问题描述】:
错误表明该系列的真值不明确。错误发生在第 8 行。 我不确定我在这个 for 循环中做错了什么。如果您想查看数据框,我可以将其发布在 GitHub 上。提前感谢您的帮助!
1) charged_off = 0
2) fully_paid = 0
3) percentages = []
4) index = []
5)
6) for var in emp_length:
7) for i in range(0,10):
8) if loan['emp_length'] == emp_length[i] and loan['loan_status'] == 'Charged Off':
9) charged_off = +1
10) else: fully_paid = +1
11)
12) percentages.append((charged_off / (charged_off + fully_paid))*100)
13)
14) print(percentages)
emp_length 变量(列表输出): ['1年', '10 年以上', '2年', '3年', '4年', '5年', '6年', '7年', '8年', '9年', '
error message screenshot is here
loan['loan_status'].unique() 输出:array(['Fully Paid', 'Charged Off'], dtype=object)
【问题讨论】:
标签: python pandas for-loop series