Session Ready
Exercise

Shifting stock prices across time

The first method to manipulate time series that you saw in the video was .shift(), which allows you shift all values in a Series or DataFrame by a number of periods to a different time along the DateTimeIndex.

Let's use this to visually compare a stock price series for Google shifted 90 business days into both past and future.

Instructions
100 XP

We have already imported pandas as pd and matplotlib.pyplot as plt.

  • Use pd.read_csv() to import 'google.csv', parsing the 'Date' as dates, setting the result as index and assigning to google.
  • Use .asfreq() to set the frequency of google to business daily.
  • Add new columns lagged and shifted to google that contain the Close shifted by 90 business days into past and future, respectively.
  • Plot the three columns of google.