[英]How to Use the Returned Value (a list) from one function in a new function to print the list as a csv at the user's desired file path
def find_qualifying_loans(bank_data, credit_score, debt, income, loan, home_value):
monthly_debt_ratio = calculate_monthly_debt_ratio(debt, income)
print(f"The monthly debt to income ratio is {monthly_debt_ratio:.02f}")
# Calculate loan to value ratio
loan_to_value_ratio = calculate_loan_to_value_ratio(loan, home_value)
print(f"The loan to value ratio is {loan_to_value_ratio:.02f}.")
# Run qualification filters
bank_data_filtered = filter_max_loan_size(loan, bank_data)
bank_data_filtered = filter_credit_score(credit_score, bank_data_filtered)
bank_data_filtered = filter_debt_to_income(monthly_debt_ratio, bank_data_filtered)
bank_data_filtered = filter_loan_to_value(loan_to_value_ratio, bank_data_filtered)
print(f"Found {len(bank_data_filtered)} qualifying loans")
return bank_data_filtered
def save_qualifying_loans(qualifying_loans)
This new function is supposed to first verify if the amount of qualifying loans is 'None', in which the program can terminate after a goodbye message.这个新的 function 应该首先验证合格贷款的数量是否为“无”,其中程序可以在再见消息后终止。 Next, if there are qualifying loans, I need to save the qualifying loans from above found in the return value 'bank_data_filtered' as a csv file.
接下来,如果有符合条件的贷款,我需要将上面在返回值“bank_data_filtered”中找到的符合条件的贷款保存为 csv 文件。 The program user is supposed to select the desired output path on their computer.
程序用户应该在他们的计算机上 select 所需的 output 路径。 How do I even begin writing this new function?
我什至如何开始编写这个新的 function? Thank you.
谢谢你。
Something like this?像这样的东西?
import pandas as pd
import os
df = pd.DataFrame({'name': ['Raphael', 'Donatello'],
'mask': ['red', 'purple'],
'weapon': ['sai', 'bo staff']})
def saveCsv(df,filepath, filename):
df.to_csv(os.path.join(filepath,filename))
saveCsv(df,filepath='/home/ashleyubuntu/Documents',filename='df.csv')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.