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.
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.
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.
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.
Api usage is currently unlimited, but throttled. For more information see our api page.
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.
Please make sure you are using the latest version of the python package, in order to access multiple dataset functionality.
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")
mydata = Quandl.get("NSE/OIL", collapse="annual")
mydata = Quandl.get("NSE/OIL", transformation="rdiff")
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.
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.
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.