I'm new to programming and python,
I'm trying to create a function to iterate over a dataframe and directly store results from the function to dataframe, so far here is what I've done:
def principal_loop2(df, col1, col2, col3):
for i, row in df_principal.iterrows():
balance = row[col1]
Suku_bunga = row[col2]
terms = int(row[col3])
periode = range(1, terms+1)
if balance > 0:
p = npf.ppmt(
rate=Suku_bunga/12, per=periode, nper=terms, pv=-balance
)
return (p)
after running it I'm able to get the NumPy array from p and store it to a variable then transform it into dataframe, but that's only work in the first datapoint since the return exits the function after it satisfies the first condition. What alternative I can do so Im able to get all the results from the function as a NumPy array or directly save it to dataframe
thank you