Use interpolation to create weekly employment data
You have recently used the civilian US unemployment rate, and converted it from monthly to weekly frequency using simple forward
or backfill
methods.
Compare your previous approach to the new .interpolate()
method that you learned about in this video.
This exercise is part of the course
Manipulating Time Series Data in Python
Exercise instructions
We have imported pandas
as pd
and matplotlib.pyplot
as plt
for you. We have also loaded the monthly unemployment rate from 2010 to 2016 into a variable monthly
.
- Inspect
monthly
using.info()
. - Create a
pd.date_range()
with weekly dates, using the.min()
and.max()
of theindex
ofmonthly
asstart
andend
, respectively, and assign the result toweekly_dates
. - Apply
.reindex()
usingweekly_dates
tomonthly
and assign the output toweekly
. - Create new columns
'ffill'
and'interpolated'
by applying.ffill()
and.interpolate()
toweekly.UNRATE
. - Show a plot of
weekly
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Inspect data here
print(____)
# Create weekly dates
weekly_dates = ____
# Reindex monthly to weekly data
weekly = ____
# Create ffill and interpolated columns
weekly['ffill'] = ____
weekly['interpolated'] = ____
# Plot weekly