Getting Quandl Data via Pandas Data-Reader

Question:

I am having trouble using pandas-datareader to import data from Quandl. Here is the code that I have tried (with a real API key):

import pandas_datareader.data as pdr
from datetime import date

start=date(1970,1,1)
end=date.today()
ticker='F'
qkey=[My API Key]

pdr.QUANDL_API_KEY=qkey
QUANDL_API_KEY=qkey
pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end)      
pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end,api_key=qkey)

I get the following error messages when I run this:

>>> pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:Python37libsite-packagespandas_datareaderdata.py", line 379, in DataReader
    session=session, api_key=access_key).read()
  File "C:Python37libsite-packagespandas_datareaderquandl.py", line 54, in __init__
    raise ValueError('The Quandl API key must be provided either '
ValueError: The Quandl API key must be provided either through the api_key variable or through the environmental variable QUANDL_API_KEY.
>>> pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end,api_key=qkey)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: DataReader() got an unexpected keyword argument 'api_key'

What am I missing? How do I provide the API key?

Asked By: Kalev Maricq

||

Answers:

The source shows how the DataReader factory function passes it to the Quandl reader:

elif data_source == "quandl":
        return QuandlReader(symbols=name, start=start, end=end,
                            retry_count=retry_count, pause=pause,
                            session=session, api_key=access_key).read()

So try passing it to DataReader with the access_key argument:

pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end,access_key=qkey)
Answered By: lehiester

A slightly different approach to quandl

import quandl 
quandl.ApiConfig.api_key = "API-KEY"
aapl = quandl.get("WIKI/TICKER", start_date="YEAR-MONTH-DAY", end_date="YEAR-MONTH-DAY")
Answered By: Marcell Kovacs

Configuration

  • MAC OS
  • VS Code
  • Python 3.x

Method

  • Run this code:
import pandas_datareader.data as pdr
api_key = [YOUR_API_KEY]
pdrquandl = pdr.DataReader("WIKI/TICKER", 'quandl', start_date, end_date, api_key)
Answered By: cryptomamy
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.