CommencerCommencer gratuitement

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'.

Cet exercice fait partie du cours

Importing and Managing Financial Data in Python

Afficher le cours

Instructions

  • 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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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()
Modifier et exécuter le code