Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda 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

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 2

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookLoan Portfolio Analysis with Pandas

Deslize para mostrar o menu

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

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 2
some-alt