Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Loan Portfolio Analysis with Pandas | Risk Assessment and Loan Analytics
Python for Bankers

bookLoan 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.

123456789101112
import 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)
copy

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))
copy

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?

question mark

How can you filter a DataFrame to show only high-risk loans?

Select the correct answer

question mark

What is the benefit of calculating the average interest rate for a loan portfolio?

Select the correct answer

question mark

Which DataFrame method is used to sort loans by risk score?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 2

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

bookLoan Portfolio Analysis with Pandas

Pyyhkäise näyttääksesi valikon

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.

123456789101112
import 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)
copy

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))
copy

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?

question mark

How can you filter a DataFrame to show only high-risk loans?

Select the correct answer

question mark

What is the benefit of calculating the average interest rate for a loan portfolio?

Select the correct answer

question mark

Which DataFrame method is used to sort loans by risk score?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 2
some-alt