1. Learn
  2. /
  3. Courses
  4. /
  5. Visualizing Time Series Data in Python

Connected

Exercise

Plot monthly and yearly trends

Like we saw in Chapter 2, when the index of a DataFrame is of the datetime type, it is possible to directly extract the day, month or year of each date in the index. As a reminder, you can extract the year of each date in the index using the .index.year attribute. You can then use the .groupby() and .mean() methods to compute the mean annual value of each time series in your DataFrame:

index_year = df.index.year
df_by_year = df.groupby(index_year).mean()

You will now apply what you have learned to display the aggregate mean values of each time series in the jobs DataFrame.

Instructions 1/2

undefined XP
    1
    2
  • Extract the month for each of the dates in the index of jobs and assign them to index_month.
  • Compute the monthly mean unemployment rate in jobs and assign it to jobs_by_month.
  • Plot all the columns of jobs_by_month.