Visualize the distribution of your data

Importing and Managing Financial Data in Python

Stefan Jansen

Instructor

Always look at your data!

  • Identical metrics can represent very different data

alwayslook.png

Importing and Managing Financial Data in Python

Introducing seaborn plots

  • Many attractive and insightful statistical plots
  • Based on matplotlib
  • Swiss Army knife: seaborn.distplot()
    • Histogram
    • Kernel Density Estimation (KDE)
    • Rugplot
Importing and Managing Financial Data in Python

10 year treasury: trend and distribution

ty10 = web.DataReader('DGS10', 'fred', date(1962, 1, 1))
ty10.info()
DatetimeIndex: 15754 entries, 1962-01-02 to 2022-05-20
Data columns (total 1 columns):
 #   Column  Non-Null Count  Dtype  
 --  ------  --------------  -----  
 0   DGS10   15083 non-null  float64
ty10.describe()
              DGS10
mean       6.291073
std        2.851161
min        1.370000
25%        4.190000
50%        6.040000
...
Importing and Managing Financial Data in Python

10 year treasury: time series trend

ty10.dropna(inplace=True) # Avoid creation of copy

ty10.plot(title='10-year Treasury'); plt.tight_layout()

10yrtreasury.png

Importing and Managing Financial Data in Python

10 year treasury: historical distribution

import seaborn as sns
sns.distplot(ty10)

10yrhist.png

Importing and Managing Financial Data in Python

10 year treasury: trend and distribution

ax = sns.distplot(ty10)
ax.axvline(ty10['DGS10'].median(), color='black', ls='--')

10yrdensity.png

Importing and Managing Financial Data in Python

Let's practice!

Importing and Managing Financial Data in Python

Preparing Video For Download...