Install

conda install quandl

Imports

In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
import quandl

Set API Key

In [4]:
# quandl.ApiConfig.api_key = "Your api key here"

Make a Basic Data Call

This call gets the WTI Crude Oil price from the US Department of Energy. Note that you need to know the Quandl code of each dataset you download. For this example, it is "EIA/PET_RWTC_D".:

In [5]:
mydata = quandl.get("EIA/PET_RWTC_D")
In [6]:
mydata.head()
Out[6]:
Value
Date
1986-01-02 25.56
1986-01-03 26.00
1986-01-06 26.53
1986-01-07 25.85
1986-01-08 25.87

Plot the Data

In [7]:
mydata.plot(figsize=(12,6))
Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x8da5eb0>

Change Formats

You can get the same data in a NumPy array:

In [8]:
mydata = quandl.get("EIA/PET_RWTC_D", returns="numpy")
mydata
Out[8]:
rec.array([(datetime.datetime(1986, 1, 2, 0, 0), 25.56),
           (datetime.datetime(1986, 1, 3, 0, 0), 26.  ),
           (datetime.datetime(1986, 1, 6, 0, 0), 26.53), ...,
           (datetime.datetime(2018, 3, 1, 0, 0), 60.98),
           (datetime.datetime(2018, 3, 2, 0, 0), 61.19),
           (datetime.datetime(2018, 3, 5, 0, 0), 62.49)],
          dtype=[('Date', 'O'), ('Value', '<f8')])

Specifying Data

To set start and end dates:

In [9]:
mydata = quandl.get("FRED/GDP", start_date="2001-12-31", end_date="2005-12-31")
In [10]:
mydata.head()
Out[10]:
Value
Date
2002-01-01 10834.445
2002-04-01 10934.752
2002-07-01 11037.057
2002-10-01 11103.834
2003-01-01 11230.078

Request a Single Column

In [11]:
mydata = quandl.get(["NSE/OIL.1", "WIKI/AAPL.4"])
In [12]:
mydata.head()
Out[12]:
NSE/OIL - Open WIKI/AAPL - Close
Date
1980-12-12 NaN 28.75
1980-12-15 NaN 27.25
1980-12-16 NaN 25.25
1980-12-17 NaN 25.87
1980-12-18 NaN 26.63

Usage Limits

The Quandl Python module is free. If you would like to make more than 50 calls a day, however, you will need to create a free Quandl account and set your API key:

In [ ]:
# EXAMPLE
quandl.ApiConfig.api_key = "YOUR_KEY_HERE"
mydata = quandl.get("FRED/GDP")

Database Codes

Each database on Quandl has a short (3-to-6 character) database ID. For example:

  • CFTC Commitment of Traders Data: CFTC
  • Core US Stock Fundamentals: SF1
  • Federal Reserve Economic Data: FRED

Each database contains many datasets. Datasets have their own IDs which are appended to their parent database ID, like this:

  • Commitment of traders for wheat: CFTC/W_F_ALL
  • Market capitalization for Apple: SF1/AAPL_MARKETCAP
  • US civilian unemployment rate: FRED/UNRATE

You can download all dataset codes in a database in a single API call, by appending /codes to your database request. The call will return a ZIP file containing a CSV.

Every Quandl code has 2 parts: the database code (“WIKI”) which specifies where the data comes from, and the dataset code (“FB”) which identifies the specific time series you want.

You can find Quandl codes on their website, using their data browser.

https://www.quandl.com/search

Example: Stocks

In [23]:
mydata = quandl.get('WIKI/FB',start_date='2015-01-01',end_date='2017-01-01')
In [24]:
mydata.head()
Out[24]:
Open High Low Close Volume Ex-Dividend Split Ratio Adj. Open Adj. High Adj. Low Adj. Close Adj. Volume
Date
2015-01-02 78.58 78.9300 77.700 78.450 18177475.0 0.0 1.0 78.58 78.9300 77.700 78.450 18177475.0
2015-01-05 77.98 79.2455 76.860 77.190 26452191.0 0.0 1.0 77.98 79.2455 76.860 77.190 26452191.0
2015-01-06 77.23 77.5900 75.365 76.150 27399288.0 0.0 1.0 77.23 77.5900 75.365 76.150 27399288.0
2015-01-07 76.76 77.3600 75.820 76.150 22045333.0 0.0 1.0 76.76 77.3600 75.820 76.150 22045333.0
2015-01-08 76.74 78.2300 76.080 78.175 23960953.0 0.0 1.0 76.74 78.2300 76.080 78.175 23960953.0

Get a Single Column Data

In [25]:
mydata = quandl.get('WIKI/FB.1',start_date='2015-01-01',end_date='2017-01-01')
In [26]:
mydata.head()
Out[26]:
Open
Date
2015-01-02 78.58
2015-01-05 77.98
2015-01-06 77.23
2015-01-07 76.76
2015-01-08 76.74
In [27]:
mydata = quandl.get('WIKI/FB.7',start_date='2015-01-01',end_date='2017-01-01')
In [28]:
mydata.head()
Out[28]:
Split Ratio
Date
2015-01-02 1.0
2015-01-05 1.0
2015-01-06 1.0
2015-01-07 1.0
2015-01-08 1.0

Example: Housing Price Example

Zillow Home Value Index (Metro): Zillow Rental Index - All Homes - San Francisco, CA

The Zillow Home Value Index is Zillow's estimate of the median market value of zillow rental index - all homes within the metro of San Francisco, CA. This data is calculated by Zillow Real Estate Research (www.zillow.com/research) using their database of 110 million homes.

In [34]:
houses = quandl.get('ZILLOW/M11_ZRIAH')
In [35]:
houses.head()
Out[35]:
Value
Date
2010-11-30 2240.0
2010-12-31 2253.0
2011-01-31 2275.0
2011-02-28 2304.0
2011-03-31 2333.0
In [36]:
houses.plot()
Out[36]:
<matplotlib.axes._subplots.AxesSubplot at 0x2ae07d12dd8>