123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import consts
- import numpy as np;# 近3月开户最高贷款本金
- import utils
- import time;
- #近3月开户最高贷款本金
- def getLastLoanAmtMax(df,reportTime,month):
- openAccoutDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
- return np.max(openAccoutDf['借款金额(本金)'])
- #近3月开户最高贷款本金
- def getLastLoanAmtMin(df,reportTime,month):
- openAccoutDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
- return np.min(openAccoutDf['借款金额(本金)'])
- #近3月开户最高贷款本金
- def getLastLoanAmtAvg(df,reportTime,month):
- openAccoutDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
- return round(np.mean(openAccoutDf['借款金额(本金)']),2)
- #贷款最近一次还款日期距今时长
- #从“贷款信息”中提取,取客户的正常还款行为,不取因为某种特定的行为而产生的还款,
- # 剔除转出、结清、呆账、呆帐后,取各贷款记录的“最近一次还款日期”的最小值,然后计算距离报告时间的天数,MIN(day(报告时间-最近一次还款日期))
- def getLastPayDateMinDays(df,reportTime):
- return utils.difDateReportTime(reportTime,np.max(df['最近一次还款日期']))
- #从“贷款信息”计算客户符合以下条件的贷款额度
- # 1.近12个月(开户日期<90)
- # 2.贷款额度>100元
- # 3.贷款类型=‘个人消费贷款’
- def getLastPerConsumeAmt(df,month,reportTime):
- openAccountDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
- openAccountDf = openAccountDf[(openAccountDf['借款金额(本金)']>100) & (openAccountDf['业务种类']=='其他个人消费贷款')]
- return round(np.sum(openAccountDf['借款金额(本金)']),2)
- #当前贷款
- def getCurLtv(tmpDf,bizTypeList):
- ltvDf = tmpDf[tmpDf['业务种类'].isin(bizTypeList)]
- key = bizTypeList[0][-1];
- if len(key)==1:
- rules = r'.*?'+key+'.*'
- houseDf = tmpDf[tmpDf['业务种类'].str.contains(rules)]
- ltvDf.append(houseDf)
- if not ltvDf.empty:
- return round(np.divide(np.sum(ltvDf['余额(本金)'].astype('int')), np.sum(ltvDf['借款金额(本金)'].astype('int'))), 2)
- return None
- #按管理机构类型统计当前贷款比例
- def getCurBankLtv(tmpDf,bizTypeList):
- ltvDf = tmpDf[tmpDf['管理机构类型'].isin(bizTypeList)]
- if not ltvDf.empty:
- return round(np.divide(np.sum(ltvDf['余额(本金)'].astype('int')), np.sum(ltvDf['借款金额(本金)'].astype('int'))), 2)
- return None
- #贷款开户数
- def getOpenAccount(df,reportTime,month,bizTypeList):
- tmpDf = df
- if not tmpDf.empty:
- if len(bizTypeList)>0:
- tmpDf = tmpDf[tmpDf['管理机构类型'].isin(bizTypeList)];
- tmpDf = tmpDf.sort_values(by=["开立日期"], ascending=(False))
- openAccountDf = tmpDf[tmpDf['开立日期'] >= utils.getLastMonthDate(reportTime, month)]
- return openAccountDf.index.size
- return 0;
- #计算最大授信额度-汇算帐0630
- def getLoanCreditAmtMax(df,reportTime,month):
- loanCreditAmtDf = df[df['担保方式'].isin(['信用/免担保'])]
- loanCreditAmtDf = loanCreditAmtDf[(~loanCreditAmtDf['业务种类'].isin(consts.notMortgageList))]
- creditDate = utils.getLastMonthDate(reportTime, month)
- loanCreditAmtDf = loanCreditAmtDf[loanCreditAmtDf["开立日期"] >= creditDate]
- if not loanCreditAmtDf.empty:
- return np.max(loanCreditAmtDf['借款金额(本金)'])
- else:
- return None
- #小额贷款笔数近1个月小额贷款笔数
- def getSmallLoanCount(df,reportTime,month):
- openAccoutDf = df[df['开立日期']>=utils.getLastMonthDate(reportTime,month)]
- if not openAccoutDf.empty:
- smallDf = openAccoutDf[openAccoutDf['借款金额(本金)']<=20000]
- return smallDf.index.size
- return None
|