Help > Quandl Python App

Using Quandl from Python

Quandl's free Python app allows you to access Quandl data directly from within Python.

If you haven't already read Quandl's API documentation, we recommend you do so before proceeding.

Installation

Quandl is available as a free Python package on PyPi and on GitHub.

To install from PyPi, follow the standard Python package installation procedure.

To install from Github, simply download the Quandl folder and place it in your Python library folder, or edit your PYTHONPATH file.

Quandl requires the numpy (version 1.8 or greater) and pandas (version 0.14 or greater) libraries in order to work.

Authentication

To make more than 50 calls a day, you will need an authentication token. You can find your token under the API tab on your account page.

If you don't have a Quandl account, registering is free and only takes a few seconds. You can learn more about usage rules on our API page. We offer unlimited usage to anyone who asks!

Once you have your token, simply include it with your first function call, like this:

import Quandl
mydata = Quandl.get("NSE/OIL", authtoken="your token here")

It will then be stored in your working directory for continued use.

Basic Use

Here's a basic Quandl data call:

import Quandl
mydata = Quandl.get("WIKI/AAPL")

The Quandl package is able to return data in 2 formats: a pandas data series ("pandas") and a numpy array ("numpy"). "pandas" is the default. Here's how you specify the format explicitly:

mydata = Quandl.get("WIKI/AAPL",returns="numpy")

You can get multiple datasets in one call by passing an array of Quandl codes, like this:

mydata = Quandl.get(["NSE/OIL.4","WIKI/AAPL.1"])

This grabs the 4th column of dataset NSE/OIL and the 1st column of dataset WIKI/AAPL, and returns them in a single call.

Data Manipulation

Just like the basic API, the Python package offers various ways to manipulate or transform the data prior to download:

Specific Date Range:

mydata = Quandl.get("NSE/OIL", trim_start="yyyy-mm-dd", trim_end="yyyy-mm-dd")

Frequency Change:

mydata = Quandl.get("NSE/OIL", collapse="annual")
("daily"|weekly"|"monthly"|"quarterly"|"annual")

Transformations:

mydata = Quandl.get("NSE/OIL", transformation="rdiff")
("diff"|"rdiff"|"normalize"|"cumul")

Return last n rows:

mydata = Quandl.get("NSE/OIL", rows=5)

(These transformations are documented more fully on our API page.)

You can search Quandl for datasets from within Python. Here is an example search:

datasets = Quandl.search(query = "crude oil", source = "DOE", page = 2, prints = True)

The only mandatory parameter is "query". "page" specifies which page of search results you wish to see (default=1). "source" specifies that you want to search within a particular data source (default=all data sources). "prints" specifies whether or not you want to see the first 3 results on the console.

Cheat Sheet

We have created a simple cheat sheet for Python users; it covers basic usage of the NumPy, SciPy and Pandas libraries, vector and matrix operations, time series manipulation, plotting, and Quandl data access. You can download the cheat sheet here.

Feedback

Please do email us with suggestions, feedback, bug reports, feature requests or code contributions. Thank you for your support!

Our thanks to Mark Hartney, Oliver Sherouse and Jeremiah Lowin for their help with this package.