我是Python的新手,我已提取SQL数据并将其放在数据框中。在调用我创建的以下函数时,如果选择长度为4,则会得到预期的结果。如果在调用函数时给出较少/较多的列表值,则会出现“列表索引超出范围”错误。我相信我可以使用while语句,能帮上忙吗??
overdue_days =(loanapp_df [[''credit_day_overdue','name_income_type']])。values choice =([['工作中','公务员','商业伙伴','养老金领取者'])
def过度(a): 逾期1 =支付1 =逾期2 =支付2 =逾期3 =支付3 =逾期4 =支付4 =逾期5 =支付5 = 0 在以下方面缴纳会费: 如果dues [1] == choice [0]和dues [0]> 0: 逾期1 =逾期1 + 1 如果dues [1] == choice [0]和dues [0] == 0: 已支付1 =已支付1 + 1 如果dues [1] == choice [1]和dues [0]> 0: 逾期2 =逾期2 + 1 如果dues [1] == choice [1]和dues [0] == 0: 已支付2 =已支付2 + 1 如果dues [1] == choice [2]和dues [0]> 0: 逾期3 =逾期3 + 1 如果dues [1] == choice [2]和dues [0] == 0: 已付费3 =已付费3 + 1 如果dues [1] == choice [3]和dues [0]> 0: 逾期4 =逾期4 + 1 如果dues [1] == choice [3]和dues [0] == 0: paid4 = paid4 + 1
print("\n********Compare paid applicants vs overdue applicants*******************************")
print("\n The number of "+choice[0]+" applicants for overdues are : {} and paid are {}\n ".format(overdue1,paid1)+
"The number of "+choice[1]+" applicants for overdues are : {} and paid are {}\n ".format(overdue2,paid2)+
"The number of "+choice[2]+" applicants for overdues are : {} and paid are {}\n ".format(overdue3,paid3)+
"The number of "+choice[3]+" applicants for overdues are : {} and paid are {}\n ".format(overdue4,paid4))
逾期(逾期天数)
overdue_days =(loanapp_df [[''credit_day_overdue','name_family_status']])。values 选择= [['单身/未婚','已婚','公婚','寡妇']) 逾期(overdue_days)
overdue_days =(loanapp_df [[''credit_day_overdue','name_contract_type']])。values choice =([['现金贷款','循环贷款']) 逾期(overdue_days)