Reading third-party financial data using APIs
In this recipe, you will use a very useful library, pandas-datareader
, which provides remote data access so that you can extract data from multiple data sources, including Yahoo Finance, Quandl, and Alpha Vantage, to name a few. The library not only fetches the data but also returns the data as a pandas DataFrame and the index as a DatetimeIndex
.
Getting ready
For this recipe, you will need to install pandas-datareader
.
To install it using conda
, run the following command:
>>> conda install -c anaconda pandas-datareader -y
To install it using pip
, run the following command:
>>> pip install pandas-datareader
How to do it…
In this recipe, you will use the Yahoo API to pull stock data for Microsoft and Apple. Let's get started:
- Let's start by importing the necessary libraries:
import pandas as pd import datetime import matplotlib.pyplot as plt import pandas_datareader.data...