Getting stock market data
Start by importing the packages. We will need pandas and the pandas_datareader.
# Import modules
import pandas as pd
from pandas_datareader import data
Datareader allows you to import data from the internet. I have found that Quandl and robinhood works the best as a source for stockmarket data.
Note that if you want an other type of data (e.g. GDP, inflation, etc.) other sources exist.
#import stock from robinhood
aapl_robinhood = data.DataReader('AAPL', 'robinhood', '1980-01-01')
aapl_robinhood.head()
close_price | high_price | interpolated | low_price | open_price | session | volume | ||
---|---|---|---|---|---|---|---|---|
symbol | begins_at | |||||||
AAPL | 2017-08-04 | 153.996200 | 154.990700 | False | 153.306900 | 153.681100 | reg | 20559852 |
2017-08-07 | 156.379100 | 156.487400 | False | 154.272000 | 154.655900 | reg | 21870321 | |
2017-08-08 | 157.629700 | 159.352900 | False | 155.847400 | 156.172300 | reg | 36205896 | |
2017-08-09 | 158.594700 | 158.801500 | False | 156.674500 | 156.822200 | reg | 26131530 | |
2017-08-10 | 153.543100 | 158.169600 | False | 152.861000 | 158.070700 | reg | 40804273 |
#import stock from quandl
aapl_quandl = data.DataReader('AAPL', 'quandl', '1980-01-01')
aapl_quandl.head()
Open | High | Low | Close | Volume | ExDividend | SplitRatio | AdjOpen | AdjHigh | AdjLow | AdjClose | AdjVolume | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Date | ||||||||||||
2018-03-27 | 173.68 | 175.15 | 166.92 | 168.340 | 38962839.0 | 0.0 | 1.0 | 173.68 | 175.15 | 166.92 | 168.340 | 38962839.0 |
2018-03-26 | 168.07 | 173.10 | 166.44 | 172.770 | 36272617.0 | 0.0 | 1.0 | 168.07 | 173.10 | 166.44 | 172.770 | 36272617.0 |
2018-03-23 | 168.39 | 169.92 | 164.94 | 164.940 | 40248954.0 | 0.0 | 1.0 | 168.39 | 169.92 | 164.94 | 164.940 | 40248954.0 |
2018-03-22 | 170.00 | 172.68 | 168.60 | 168.845 | 41051076.0 | 0.0 | 1.0 | 170.00 | 172.68 | 168.60 | 168.845 | 41051076.0 |
2018-03-21 | 175.04 | 175.09 | 171.26 | 171.270 | 35247358.0 | 0.0 | 1.0 | 175.04 | 175.09 | 171.26 | 171.270 | 35247358.0 |