Skip to content

Commit 04f3788

Browse files
authored
Quandl stock data pull script
1 parent ef1c723 commit 04f3788

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Tutorials/Quandl Script.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# import needed libraries
2+
import quandl
3+
import pandas as pd
4+
5+
# add quandl API key for unrestricted
6+
quandl.ApiConfig.api_key = 'INSERT YOU API KEY HERE'
7+
8+
# get the table for daily stock prices and,
9+
# filter the table for selected tickers, columns within a time range
10+
# set paginate to True because Quandl limits tables API to 10,000 rows per call
11+
data = quandl.get_table('WIKI/PRICES', ticker = ['AAPL', 'MSFT', 'WMT'],
12+
qopts = { 'columns': ['ticker', 'date', 'adj_close'] },
13+
date = { 'gte': '2015-12-31', 'lte': '2016-12-31' },
14+
paginate=True)
15+
16+
# create a new dataframe with 'date' column as index
17+
new = data.set_index('date')
18+
19+
# use pandas pivot function to sort adj_close by tickers
20+
clean_data = new.pivot(columns='ticker')

0 commit comments

Comments
 (0)