Exercise

Get stock data for a single company

DataReader offers the data source 'iex'. To experiment with the data outside DataCamp environment, you will need an IEX Cloud account.

IEX limits access to stock price series to the last five years.

Retrieving stock price data from IEX is simple after importing the DataReader package and using the start and/or end arguments in form date(YYYY, MM, DD):

stock_data = DataReader(ticker, data_source, start, end)

In the first chapter, you learned that a stock ticker is the unique symbol needed to get stock information for a certain company.

In this exercise, you will practice importing the 2016 data for Apple, with ticker 'AAPL'.

Instructions

100 XP
  • Import the DataReader from pandas_datareader.data and date from the datetime library.
  • Using date(), set the start date to January 1, 2016 and end date to December 31, 2016.
  • Set ticker to Apple's stock ticker 'AAPL' and data_source to 'iex'.
  • Create a DataReader() object to import the stock prices and assign to a variable stock_prices.
  • Use .head() and .info() to display and inspect the result.