Exercise: Stock prices

In [1]:
import pandas as pd
%matplotlib inline

If you have installed pandas_datareader, please download current stock prices using this:

import pandas_datareader.data as web
s = web.DataReader(['AAPL', 'GOOG', 'TSLA'], data_source='yahoo', start='2020')

Alternately, load from a file where data from until yesterday was saved. Download the file from D2L and move it to the right place in order for the following cell to work.

In [2]:
s = pd.read_pickle('../../data_external/stock_prices.pkl')

In either case, you will end up with a data frame s which contains three categories of prices for three tech stocks.

Tasks:

  • Find out if a heirarchical indexing (MultiIndex) is being used in this data.
  • Access and plot the closing price of AAPL on all days in the data.
  • Print the closing price of all three stocks yesterday.
  • Extract a smaller data frame with no MultiIndex containing only TSLA data.