Sunday, May 27, 2018

FRED Data with pandas_datareader

FRED data with pandas_datareader

The Federal Reserve Bank of St. Louis publishes a lot of series and has a simple API. Below we take a really quick look at a couple of unemployment series. Really quick because it's just a couple lines beyond the expected imports.

Imports

In [2]:
# imports
import pandas as pd
from datetime import datetime as dt
pd.core.common.is_list_like = pd.api.types.is_list_like # workaround
import pandas_datareader.data as pdd
import matplotlib.pyplot as plt

# CONST
Sdt = dt(1990, 1, 1) # negative infinity date
Edt = dt(2020, 1, 1) # future date 
SW = "HSGS2564W" # Unemployment Rate - High School Graduates, No College, 25 to 64 years, Women
SM = "HSGS2564M" # Unemployment Rate - High School Graduates, No College, 25 to 64 years, Men

Grab data with DataReader

Arguments are

  • series wanted or a list of series wanted
  • constant "fred" to indicate we are reading from FRED. Could have supplied instead "google" for Google Finance, or "ff" for Kenneth French's data library
  • earliest datetime wanted
  • latest datetime wanted

There are some additional arguments not use here. For more details, help(pdd.DataReader).

In [3]:
# grab data
noCollegeDF = pdd.DataReader((SW, SM), "fred", Sdt, Edt)
noCollegeDF.head()
Out[3]:
HSGS2564W HSGS2564M
DATE
2000-01-01 3.8 3.7
2000-02-01 3.7 4.1
2000-03-01 3.5 3.8
2000-04-01 3.0 3.5
2000-05-01 3.5 2.9

Plot

In [4]:
%matplotlib inline  
fig, ax = plt.subplots() 
noCollegeDF.plot(ax=ax)
plt.title("Unemployment for HS Grads with No College W and M")
Out[4]:
Text(0.5,1,'Unemployment for HS Grads with No College W and M')

1 comment: