Libraries: Requires pandas_datareader to be installed. In terminal paste “pip install pandas-datareader”
Python’s most popular library for working with time series data is called pandas. This library allows you to download stock price data and other financial data from Yahoo Finance, Google Finance, St. Louis FED (FRED), Kenneth French’s data library, World Bank, and Google Analytics.

To download stock price data from Yahoo Finance, we import the DataReader tool as follows:

We also import the datetime library to handle date-type data, and to define the start and end dates of the time series we want to download.

To download the stock price data of a certain stock, such as Apple, simply input the required parameters ( Ticker, data_source, start date, end date) into the DataReader function as follows:

Notice that we specify that we only want the Adj Close prices. If we don’t specify this, then we would also obtain other price information such as Open, High, and Low prices as well as Volume data.

To plot the price data we downloaded for Apple we use the matplotlib.pyplot library as follows: