Create weekly from monthly unemployment data
The civilian US unemployment rate is reported monthly. You may need more frequent data, but that's no problem because you just learned how to upsample a time series.
You'll work with the time series data for the last 20 years, and apply a few options to fill in missing values before plotting the weekly series.
This exercise is part of the course
Manipulating Time Series Data in Python
Exercise instructions
We have already imported pandas as pd and matplotlib.pyplot as plt.
- Use
pd.read_csv()to import'unemployment.csv', creating aDateTimeIndexfrom the'date'column usingparse_datesandindex_col, and assign the result todata. - Convert
datato weekly frequency using.asfreq()with the alias'W'and show the first five rows. - Convert again to weekly frequency, adding the option
'bfill'and show the first five rows. - Create weekly series, now adding the option
'ffill', assign toweekly_ffilland show the first five rows. - Plot
weekly_ffillstarting in 2015.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import data here
data = ____
# Show first five rows of weekly series
print(____)
# Show first five rows of weekly series with bfill option
print(____)
# Create weekly series with ffill option and show first five rows
weekly_ffill = ____
print(____)
# Plot weekly_fill starting 2015 here