Skip to content

Instantly share code, notes, and snippets.

@finnqiao
Created June 24, 2018 07:27
Show Gist options
  • Save finnqiao/d5804829ea3fd5362a57e65f37ea68f8 to your computer and use it in GitHub Desktop.
Save finnqiao/d5804829ea3fd5362a57e65f37ea68f8 to your computer and use it in GitHub Desktop.
npl part 1
Display the source blob
Display the rendered blob
Raw
{
cells: [
{
cell_type: "markdown",
metadata: { },
source: [
"## An analysis of non-performing loan (NPL) rates globally ",
" ",
"A recent analysis of the Southeast Asian credit markets in an assignment at work brought to light some nuances regarding credit culture in this particular region. The data got me thinking about global credit health and non-performing loan rates globally. Given my recent foray into data analysis, I thought a notebook was in order. ",
" ",
"Through various data techniques, I looked into answering the following questions: ",
" 1. What are recent trends in non-performing loans globally? ",
" 2. How do core economic variables (income level, GDP etc.) impact NPL rates? ",
" 3. How important are other variables such as a nation's credit culture, market volatility, and real estate market? ",
" ",
"### But first, what is the credit market and what are non-performing loans? ",
" ",
"By examining the credit market, we are essentially looking at the market in which individuals, corporations, and governments seek to borrow money from investors. This form of borrowing can take on many different forms, from your daily credit card expenses to mortgages on your next beach home. ",
" ",
"Non-performing loans (NPL) refer to loans in which the borrower has not been able to make scheduled repayments for some time (usually over 90 days). ",
" ",
"When NPL levels rise, it is often an indicator of deteriorating credit market health. In short, more people are not paying back what they owe. ",
" ",
"We'll examine NPL levels across different countries from the World Bank databank."
]
},
{
cell_type: "markdown",
metadata: { },
source: [
"First, we start by importing the necessary packages..."
]
},
{
cell_type: "code",
execution_count: 727,
metadata: {
collapsed: true
},
outputs: [ ],
source: [
"import pandas as pd ",
"import seaborn as sb ",
"import numpy as np ",
"import matplotlib ",
"import matplotlib.pyplot as plt"
]
},
{
cell_type: "code",
execution_count: 728,
metadata: { },
outputs: [ ],
source: [
"import missingno as msno"
]
},
{
cell_type: "code",
execution_count: 729,
metadata: {
collapsed: true
},
outputs: [ ],
source: [
"from itertools import islice ",
"import csv"
]
},
{
cell_type: "markdown",
metadata: { },
source: [
"As there are some rows with filler column information, I skip the first 4 rows with islice."
]
},
{
cell_type: "code",
execution_count: 730,
metadata: { },
outputs: [
{
data: {
text/html: [
"<div> ",
"<style> ",
" .dataframe thead tr:only-child th { ",
" text-align: right; ",
" } ",
" ",
" .dataframe thead th { ",
" text-align: left; ",
" } ",
" ",
" .dataframe tbody tr th { ",
" vertical-align: top; ",
" } ",
"</style> ",
"<table border="1" class="dataframe"> ",
" <thead> ",
" <tr style="text-align: right;"> ",
" <th></th> ",
" <th>0</th> ",
" <th>1</th> ",
" <th>2</th> ",
" <th>3</th> ",
" <th>4</th> ",
" <th>5</th> ",
" <th>6</th> ",
" <th>7</th> ",
" <th>8</th> ",
" <th>9</th> ",
" <th>...</th> ",
" <th>53</th> ",
" <th>54</th> ",
" <th>55</th> ",
" <th>56</th> ",
" <th>57</th> ",
" <th>58</th> ",
" <th>59</th> ",
" <th>60</th> ",
" <th>61</th> ",
" <th>62</th> ",
" </tr> ",
" </thead> ",
" <tbody> ",
" <tr> ",
" <th>0</th> ",
" <td>Country Name</td> ",
" <td>Country Code</td> ",
" <td>Indicator Name</td> ",
" <td>Indicator Code</td> ",
" <td>1960</td> ",
" <td>1961</td> ",
" <td>1962</td> ",
" <td>1963</td> ",
" <td>1964</td> ",
" <td>1965</td> ",
" <td>...</td> ",
" <td>2009</td> ",
" <td>2010</td> ",
" <td>2011</td> ",
" <td>2012</td> ",
" <td>2013</td> ",
" <td>2014</td> ",
" <td>2015</td> ",
" <td>2016</td> ",
" <td>2017</td> ",
" <td></td> ",
" </tr> ",
" <tr> ",
" <th>1</th> ",
" <td>Aruba</td> ",
" <td>ABW</td> ",
" <td>Bank nonperforming loans to total gross loans (%)</td> ",
" <td>FB.AST.NPER.ZS</td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td>...</td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" </tr> ",
" <tr> ",
" <th>2</th> ",
" <td>Afghanistan</td> ",
" <td>AFG</td> ",
" <td>Bank nonperforming loans to total gross loans (%)</td> ",
" <td>FB.AST.NPER.ZS</td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td>...</td> ",
" <td></td> ",
" <td>49.9013229069412</td> ",
" <td>4.6968178252385</td> ",
" <td>4.95890140377645</td> ",
" <td>4.85228704838131</td> ",
" <td>7.7810908959605</td> ",
" <td>12.0536179767696</td> ",
" <td>11.0743789647307</td> ",
" <td></td> ",
" <td></td> ",
" </tr> ",
" <tr> ",
" <th>3</th> ",
" <td>Angola</td> ",
" <td>AGO</td> ",
" <td>Bank nonperforming loans to total gross loans (%)</td> ",
" <td>FB.AST.NPER.ZS</td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td>...</td> ",
" <td></td> ",
" <td>3.17305056414187</td> ",
" <td>2.01496821504011</td> ",
" <td>4.35011884491608</td> ",
" <td>7.97676918024597</td> ",
" <td>10.1905320738466</td> ",
" <td>10.6112339715733</td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" </tr> ",
" <tr> ",
" <th>4</th> ",
" <td>Albania</td> ",
" <td>ALB</td> ",
" <td>Bank nonperforming loans to total gross loans (%)</td> ",
" <td>FB.AST.NPER.ZS</td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td>...</td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" <td></td> ",
" </tr> ",
" </tbody> ",
"</table> ",
"<p>5 rows × 63 columns</p> ",
"</div>"
],
text/plain: [
" 0 1 \ ",
"0 Country Name Country Code ",
"1 Aruba ABW ",
"2 Afghanistan AFG ",
"3 Angola AGO ",
"4 Albania ALB ",
" ",
" 2 3 4 \ ",
"0 Indicator Name Indicator Code 1960 ",
"1 Bank nonperforming loans to total gross loans (%) FB.AST.NPER.ZS ",
"2 Bank nonperforming loans to total gross loans (%) FB.AST.NPER.ZS ",
"3 Bank nonperforming loans to total gross loans (%) FB.AST.NPER.ZS ",
"4 Bank nonperforming loans to total gross loans (%) FB.AST.NPER.ZS ",
" ",
" 5 6 7 8 9 ... 53 54 55 \ ",
"0 1961 1962 1963 1964 1965 ... 2009 2010 2011 ",
"1 ... ",
"2 ... 49.9013229069412 4.6968178252385 ",
"3 ... 3.17305056414187 2.01496821504011 ",
"4 ... ",
" ",
" 56 57 58 59 \ ",
"0 2012 2013 2014 2015 ",
"1 ",
"2 4.95890140377645 4.85228704838131 7.7810908959605 12.0536179767696 ",
"3 4.35011884491608 7.97676918024597 10.1905320738466 10.6112339715733 ",
"4 ",
" ",
" 60 61 62 ",
"0 2016 2017 ",
"1 ",
"2 11.0743789647307 ",
"3 ",
"4 ",
" ",
"[5 rows x 63 columns]"
]
},
execution_count: 730,
metadata: { },
output_type: "execute_result"
}
],
source: [
"all_data = [] ",
"with open('NPL.csv') as data: ",
" for row in islice(csv.reader(data), 4, None): ",
" all_data.append(np.array(row)) ",
" ",
"df = pd.DataFrame(all_data) ",
"df.head()"
]
},
{
cell_type: "code",
execution_count: 731,
metadata: { },
outputs: [
{
name: "stdout",
output_type: "stream",
text: [
"<class 'pandas.core.frame.DataFrame'> ",
"RangeIndex: 265 entries, 0 to 264 ",
"Data columns (total 63 columns): ",
"0 265 non-null object ",
"1 265 non-null object ",
"2 265 non-null object ",
"3 265 non-null object ",
"4 265 non-null object ",
"5 265 non-null object ",
"6 265 non-null object ",
"7 265 non-null object ",
"8 265 non-null object ",
"9 265 non-null object ",
"10 265 non-null object ",
"11 265 non-null object ",
"12 265 non-null object ",
"13 265 non-null object ",
"14 265 non-null object ",
"15 265 non-null object ",
"16 265 non-null object ",
"17 265 non-null object ",
"18 265 non-null object ",
"19 265 non-null object ",
"20 265 non-null object ",
"21 265 non-null object ",
"22 265 non-null object ",
"23 265 non-null object ",
"24 265 non-null object ",
"25 265 non-null object ",
"26 265 non-null object ",
"27 265 non-null object ",
"28 265 non-null object ",
"29 265 non-null object ",
"30 265 non-null object ",
"31 265 non-null object ",
"32 265 non-null object ",
"33 265 non-null object ",
"34 265 non-null object ",
"35 265 non-null object ",
"36 265 non-null object ",
"37 265 non-null object ",
"38 265 non-null object ",
"39 265 non-null object ",
"40 265 non-null object ",
"41 265 non-null object ",
"42 265 non-null object ",
"43 265 non-null object ",
"44 265 non-null object ",
"45 265 non-null object ",
"46 265 non-null object ",
"47 265 non-null object ",
"48 265 non-null object ",
"49 265 non-null object ",
"50 265 non-null object ",
"51 265 non-null object ",
"52 265 non-null object ",
"53 265 non-null object ",
"54 265 non-null object ",
"55 265 non-null object ",
"56 265 non-null object ",
"57 265 non-null object ",
"58 265 non-null object ",
"59 265 non-null object ",
"60 265 non-null object ",
"61 265 non-null object ",
"62 265 non-null object ",
"dtypes: object(63) ",
"memory usage: 130.5+ KB "
]
}
],
source: [
"df.info()"
]
}
]
metadata: {
kernelspec: {
display_name: "Python 3",
language: "python",
name: "python3"
},
language_info: {
codemirror_mode: {
name: "ipython",
version: 3
},
file_extension: ".py",
mimetype: "text/x-python",
name: "python",
nbconvert_exporter: "python",
pygments_lexer: "ipython3",
version: "3.6.3"
}
},
nbformat: 4,
nbformat_minor: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment