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'.
Este exercício faz parte do curso
Importing and Managing Financial Data in Python
Instruções do exercício
- Import the
DataReaderfrompandas_datareader.dataanddatefrom thedatetimelibrary. - Using
date(), set thestartdate to January 1, 2016 andenddate to December 31, 2016. - Set
tickerto Apple's stock ticker'AAPL'anddata_sourceto'iex'. - Create a
DataReader()object to import the stock prices and assign to a variablestock_prices. - Use
.head()and.info()to display and inspect the result.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Import DataReader
____
# Import date
____
# Set start and end dates
start = date(____)
end = date(____)
# Set the ticker
ticker = ____
# Set the data source
data_source = ____
# Import the stock prices
stock_prices = DataReader(____, ____, ____, ____)
# Display and inspect the result
print(stock_prices.head())
stock_prices.info()