Download Quandl Data¶
Install Quandl¶
!pip install quandl -q
import pandas as pd
import quandl
import matplotlib.pyplot as plt
%matplotlib inline
Get Data and Save in Pandas DataFrame¶
If run into rate limits, register at Quandl and provide api_key
in the get call.
import getpass
KEY = getpass.getpass()
df = quandl.get(
"FRED/DEXCHUS",
start_date='2014-01-01',
end_date='2020-10-01',
api_key=KEY
).rename(columns={'Value':'DEXCHUS'})
df.index.name = 'ds'
df
Plot Time Series Data¶
df.plot(figsize=(16, 10));
Find Missing Data¶
pd.date_range(
start = df.index.min(),
end = df.index.max()
).difference(df.index)
Fill Missing Data with ffill()
¶
df_ffill = df.reindex(pd.date_range(start=df.index[0], end=df.index[-1])).ffill()
# Check missing values filled '2014-01-04', '2014-01-05'
display(df_ffill.loc['2014-01-02':'2014-01-06', :])
df_ffill.loc['2014-01-02':'2014-01-06', :].plot(figsize=(16, 10));
Fill Missing Data with bfill()
¶
df_bfill = df.reindex(pd.date_range(start=df.index[0], end=df.index[-1])).bfill()
# Check missing values filled '2014-01-04', '2014-01-05'
display(df_bfill.loc['2014-01-02':'2014-01-06', :])
df_bfill.loc['2014-01-02':'2014-01-06', :].plot(figsize=(16, 10));
Fill Missing Data with Interpolation¶
df_interpolate = df.resample('D').interpolate(method='time')
# Check missing values filled '2014-01-04', '2014-01-05'
display(df_interpolate.loc['2014-01-02':'2014-01-06', :])
df_interpolate.loc['2014-01-02':'2014-01-06', :].plot(figsize=(16, 10));