Loan Portfolio Analysis with Pandas
A loan portfolio is a collection of loans held by a bank or financial institution. Each loan in the portfolio typically includes details such as the principal amount, the interest rate, and a risk score representing the likelihood of default. Analyzing a loan portfolio is crucial for understanding both the risk and profitability associated with lending activities. By examining the data, you can identify trends such as the average interest rate across all loans, spot loans that carry higher risk, and make informed decisions about risk management and pricing strategies.
123456789101112import pandas as pd # Create a DataFrame representing a portfolio of loans data = { "loan_id": [101, 102, 103, 104, 105], "principal": [50000, 75000, 120000, 45000, 90000], "interest_rate": [0.045, 0.052, 0.039, 0.060, 0.048], "risk_score": [0.15, 0.30, 0.10, 0.45, 0.25] } loans_df = pd.DataFrame(data) print(loans_df)
To extract meaningful insights from a loan portfolio, you often need to filter and sort the data. Filtering allows you to focus on loans that meet specific criteria, such as those with a risk_score above a certain threshold or with particularly high interest_rate values. Sorting helps you quickly identify the riskiest or most profitable loans by arranging them in order of risk or return. These operations make it easier to target high-risk loans for closer monitoring or to evaluate the overall quality of the portfolio.
123456789# Select loans with risk score above 0.25 (high risk) high_risk_loans = loans_df[loans_df["risk_score"] > 0.25] # Calculate the average interest rate of these high-risk loans average_interest_high_risk = high_risk_loans["interest_rate"].mean() print("High-risk loans:") print(high_risk_loans) print("Average interest rate for high-risk loans:", round(average_interest_high_risk, 4))
1. How can you filter a DataFrame to show only high-risk loans?
2. What is the benefit of calculating the average interest rate for a loan portfolio?
3. Which DataFrame method is used to sort loans by risk score?
Danke für Ihr Feedback!
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
How can I filter for loans with a lower risk score instead?
Can you show me how to sort the loans by interest rate or risk score?
What other insights can I extract from this loan portfolio data?
Großartig!
Completion Rate verbessert auf 4.76
Loan Portfolio Analysis with Pandas
Swipe um das Menü anzuzeigen
A loan portfolio is a collection of loans held by a bank or financial institution. Each loan in the portfolio typically includes details such as the principal amount, the interest rate, and a risk score representing the likelihood of default. Analyzing a loan portfolio is crucial for understanding both the risk and profitability associated with lending activities. By examining the data, you can identify trends such as the average interest rate across all loans, spot loans that carry higher risk, and make informed decisions about risk management and pricing strategies.
123456789101112import pandas as pd # Create a DataFrame representing a portfolio of loans data = { "loan_id": [101, 102, 103, 104, 105], "principal": [50000, 75000, 120000, 45000, 90000], "interest_rate": [0.045, 0.052, 0.039, 0.060, 0.048], "risk_score": [0.15, 0.30, 0.10, 0.45, 0.25] } loans_df = pd.DataFrame(data) print(loans_df)
To extract meaningful insights from a loan portfolio, you often need to filter and sort the data. Filtering allows you to focus on loans that meet specific criteria, such as those with a risk_score above a certain threshold or with particularly high interest_rate values. Sorting helps you quickly identify the riskiest or most profitable loans by arranging them in order of risk or return. These operations make it easier to target high-risk loans for closer monitoring or to evaluate the overall quality of the portfolio.
123456789# Select loans with risk score above 0.25 (high risk) high_risk_loans = loans_df[loans_df["risk_score"] > 0.25] # Calculate the average interest rate of these high-risk loans average_interest_high_risk = high_risk_loans["interest_rate"].mean() print("High-risk loans:") print(high_risk_loans) print("Average interest rate for high-risk loans:", round(average_interest_high_risk, 4))
1. How can you filter a DataFrame to show only high-risk loans?
2. What is the benefit of calculating the average interest rate for a loan portfolio?
3. Which DataFrame method is used to sort loans by risk score?
Danke für Ihr Feedback!