【对比python】逆分组 | 润乾 -pg游戏官网登录入口
任务:列出分期贷款明细,当期还款额、当期利息、当期本金、剩余本金。
python
1 | import numpy as np |
2 | import pandas as pd |
3 | loan_data = pd.read_csv('e:\\txt\\loan.csv',sep='\t') |
4 | loan_data['mrate'] = loan_data['rate']/(100*12) |
5 | loan_data['mpayment'] = loan_data['loanamt']*loan_data['mrate']*np.power(1 loan_data['mrate'],loan_data['term']) \ |
6 | /(np.power(1 loan_data['mrate'],loan_data['term'])-1) |
7 | loan_term_list = [] |
8 | for i in range(len(loan_data)): |
9 | tm = loan_data.loc[i]['term'] |
10 | loanid = np.tile(loan_data.loc[i]['loanid'],tm) |
11 | loanamt = np.tile(loan_data.loc[i]['loanamt'],tm) |
12 | term = np.arange(1,tm 1) |
13 | rate = np.tile(loan_data.loc[i]['mrate'],tm) |
14 | payment = np.tile(np.array(loan_data.loc[i]['mpayment']),loan_data.loc[i]['term']) |
15 | interest = np.zeros(len(loanamt)) |
16 | principal = np.zeros(len(loanamt)) |
17 | principalbalance = np.zeros(len(loanamt)) |
18 | loan_amt = loanamt[0] |
19 | for j in range(len(loanamt)): |
20 | interest[j] = loan_amt*loan_data.loc[i]['mrate'] |
21 | principal[j] = payment[j] - interest[j] |
22 | principalbalance[j] = loan_amt - principal[j] |
23 | loan_amt = principalbalance[j] |
24 | loan_data_df = pd.dataframe(np.transpose(np.array([loanid,loanamt,term,rate,payment,interest,principal,principalbalance])), columns = ['loanid','loanamt','term','mrate','payment','interest','principal','principalbalance']) |
25 | |
loan_term_list.append(loan_data_df) | |
26 | loan_term_pay = pd.concat(loan_term_list,ignore_index=true) |
27 | print(loan_term_pay) |
padans处理此类逆分组的问题就显得非常麻烦。
集算器
a | ||
1 | e:\\txt\\loan.csv | |
2 | =file(a1).import@t() | |
3 | =a2.derive(rate/100/12:mrate,loanamt*mrate*power((1 mrate),term)/(power((1 mrate),term)-1):mpayment) | |
4 | =a3.news((t=loanamt,term);loanid, loanamt, mpayment:payment, to(term)(#):term, mrate, t* mrate:interest, payment-interest:principal, t=t-principal:principlebalance) |
利用逆分组的函数,很容易的搞定逆分组类型的问题。