loanIndexParser.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import consts
  2. import numpy as np;# 近3月开户最高贷款本金
  3. import utils
  4. import time;
  5. #近3月开户最高贷款本金
  6. def getLastLoanAmtMax(df,reportTime,month):
  7. openAccoutDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
  8. return np.max(openAccoutDf['借款金额(本金)'])
  9. #近3月开户最高贷款本金
  10. def getLastLoanAmtMin(df,reportTime,month):
  11. openAccoutDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
  12. return np.min(openAccoutDf['借款金额(本金)'])
  13. #近3月开户最高贷款本金
  14. def getLastLoanAmtAvg(df,reportTime,month):
  15. openAccoutDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
  16. return round(np.mean(openAccoutDf['借款金额(本金)']),2)
  17. #贷款最近一次还款日期距今时长
  18. #从“贷款信息”中提取,取客户的正常还款行为,不取因为某种特定的行为而产生的还款,
  19. # 剔除转出、结清、呆账、呆帐后,取各贷款记录的“最近一次还款日期”的最小值,然后计算距离报告时间的天数,MIN(day(报告时间-最近一次还款日期))
  20. def getLastPayDateMinDays(df,reportTime):
  21. return utils.difDateReportTime(reportTime,np.max(df['最近一次还款日期']))
  22. #从“贷款信息”计算客户符合以下条件的贷款额度
  23. # 1.近12个月(开户日期<90)
  24. # 2.贷款额度>100元
  25. # 3.贷款类型=‘个人消费贷款’
  26. def getLastPerConsumeAmt(df,month,reportTime):
  27. openAccountDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
  28. openAccountDf = openAccountDf[(openAccountDf['借款金额(本金)']>100) & (openAccountDf['业务种类']=='其他个人消费贷款')]
  29. return round(np.sum(openAccountDf['借款金额(本金)']),2)
  30. #当前贷款
  31. def getCurLtv(tmpDf,bizTypeList):
  32. ltvDf = tmpDf[tmpDf['业务种类'].isin(bizTypeList)]
  33. key = bizTypeList[0][-1];
  34. if len(key)==1:
  35. rules = r'.*?'+key+'.*'
  36. houseDf = tmpDf[tmpDf['业务种类'].str.contains(rules)]
  37. ltvDf.append(houseDf)
  38. if not ltvDf.empty:
  39. return round(np.divide(np.sum(ltvDf['余额(本金)'].astype('int')), np.sum(ltvDf['借款金额(本金)'].astype('int'))), 2)
  40. return None
  41. #按管理机构类型统计当前贷款比例
  42. def getCurBankLtv(tmpDf,bizTypeList):
  43. ltvDf = tmpDf[tmpDf['管理机构类型'].isin(bizTypeList)]
  44. if not ltvDf.empty:
  45. return round(np.divide(np.sum(ltvDf['余额(本金)'].astype('int')), np.sum(ltvDf['借款金额(本金)'].astype('int'))), 2)
  46. return None
  47. #贷款开户数
  48. def getOpenAccount(df,reportTime,month,bizTypeList):
  49. tmpDf = df
  50. if not tmpDf.empty:
  51. if len(bizTypeList)>0:
  52. tmpDf = tmpDf[tmpDf['管理机构类型'].isin(bizTypeList)];
  53. tmpDf = tmpDf.sort_values(by=["开立日期"], ascending=(False))
  54. openAccountDf = tmpDf[tmpDf['开立日期'] >= utils.getLastMonthDate(reportTime, month)]
  55. return openAccountDf.index.size
  56. return 0;
  57. #计算最大授信额度-汇算帐0630
  58. def getLoanCreditAmtMax(df,reportTime,month):
  59. loanCreditAmtDf = df[df['担保方式'].isin(['信用/免担保'])]
  60. loanCreditAmtDf = loanCreditAmtDf[(~loanCreditAmtDf['业务种类'].isin(consts.notMortgageList))]
  61. creditDate = utils.getLastMonthDate(reportTime, month)
  62. loanCreditAmtDf = loanCreditAmtDf[loanCreditAmtDf["开立日期"] >= creditDate]
  63. if not loanCreditAmtDf.empty:
  64. return np.max(loanCreditAmtDf['借款金额(本金)'])
  65. else:
  66. return None
  67. #小额贷款笔数近1个月小额贷款笔数
  68. def getSmallLoanCount(df,reportTime,month):
  69. openAccoutDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
  70. if not openAccoutDf.empty:
  71. smallDf = openAccoutDf[openAccoutDf['借款金额(本金)']<=20000]
  72. return smallDf.index.size
  73. return None