0

I'm creating an amortization table and have 30 periods, index is 1-30. Problem is particular loans haven't come to the end of the 30 periods yet so I have a variable that can change each period. I have a value for 17 rows, then nothing. How do I get my variable to fill down to the 30th row with the 17th (last) value in the for loop?

beginning_bal = loan_amt principal = round(nf.ppmt(pv=loan_amt, rate=adj_interest_rate, nper=num_periods, per=num_periods, fv=0), 2) interest = nf.ipmt(pv=loan_amt, rate=adj_interest_rate, nper=num_periods, per=num_periods, fv=0) ending_bal = nf.pv(fv=0, pmt=pmt, rate=adj_interest_rate, nper=0) records=[] end_bal = loan_amt cum_int = 0.0 cof = 0.0 rt_npv = 0 for i in range(1, len(rng)+1): bgn_bal = end_bal principal = nf.ppmt(pv=loan_amt, rate=adj_interest_rate, nper=num_periods, per=i, fv=0) interest = float(nf.ipmt(pv=loan_amt, rate=adj_interest_rate, nper=num_periods, per=i, fv=0)) end_bal = nf.pv(fv=0, pmt=pmt, rate=adj_interest_rate, nper=len(rng)-i) monthly_co = loan_amt*co_rate npv_rate = 1.2**(i / num_payments_per_yr) npvper = -pmt / (npv_rate + co_rate + (.014*(12/num_payments_per_yr))) #20% discount, charge off rate, early payoff rate rt_npv += npvper cof += bgn_bal * .0083 #COF basis llr_rate.replace({'llr_rate': {0: np.nan}}).ffill() prin_llr = bgn_bal * llr_rate int_llr = -interest * llr_rate cum_int += interest net_revenue = (-cum_int - cof - monthly_co - prin_llr - int_llr) records.append((bgn_bal, -pmt, -principal, -interest, -cum_int, end_bal, monthly_co, npvper, rt_npv, npv_rate, cof, prin_llr, int_llr, net_revenue)) 
2

1 Answer 1

0

You are looking for ffill()

Explanation: Missing values are replaced with the most recent available value in the same column. So, the value of the preceding row in the same column is used to fill in the blanks.

df = df.fillna(method='ffill') 

Given this example df:

 A B C 0 1 5 10 1 2 nan 11 2 nan nan 12 3 4 8 nan 4 nan 9 14 

Result:

 A B C 0 1 5 10 1 2 8 11 2 2 8 12 3 4 8 12 4 2 9 14 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.