Get data from Quandl in Python

I found a service called Quandl that I found while researching how to get stock prices, so I tried using it.

Quandl

Quandl is a search engine for numerical data such as finance and economy, which can search data from various sources and display graphs and tables. The data can also be downloaded in JSON, CSV, and other formats, or imported into services such as Plotly.

Getting Started

There are some paid data, but most of the data can be obtained free of charge.

Libraries in various languages are also available (https://www.quandl.com/help/libraries), and you can use the API to retrieve and retrieve data.

There is a page that not only provides each data individually, but also summarizes the data. If you click Data> Data Browser from the upper left of the screen, you can search by country or data type. For example, there are the following pages.

Python library installation

Quandl libraries can be installed using pip. (Requires Numpy and pandas)

$ pip install Quandl

How to use the Python library

If you import the Quandl module and pass the Quandl Code to the get function, you can get the data as a pandas DataFrame. Quandl Code is displayed in the upper right corner of the screen when you search the data.

>>> import Quandl
>>> df = Quandl.get('GOOG/NASDAQ_GOOG')
>>> df[:5]
             Open   High    Low  Close  Volume
Date                                          
2004-08-19  49.96  51.98  47.93  50.12     NaN
2004-08-20  50.69  54.49  50.20  54.10     NaN
2004-08-23  55.32  56.68  54.47  54.65     NaN
2004-08-24  55.56  55.74  51.73  52.38     NaN
2004-08-25  52.43  53.95  51.89  52.95     NaN

[5 rows x 5 columns]

Use of tokens

If you don't have a Quandl account, you're limited to using the API 50 times a day. You can use the API unlimitedly by registering an account with Quandl and passing the token displayed on the account page together.

>>> df = Quandl.get('GOOG/NASDAQ_GOOG', authtoken='YOUR_AUTH_TOKEN')

Simultaneous acquisition of multiple data

Multiple data can be acquired at the same time by passing a list of Quandl Code as an argument as shown in the example below. This is convenient when you want to compare data.

>>> df = Quandl.get(["WORLDBANK/JPN_IT_NET_USER_P2",
...                  "WORLDBANK/KOR_IT_NET_USER_P2",
...                  "WORLDBANK/CHN_IT_NET_USER_P2"])
>>> df.columns = ["Japan", "Korea", "China"]
>>> df[:5]
               Japan     Korea     China
Date                                    
1990-12-31  0.020294  0.023265  0.000000
1991-12-31  0.040438  0.046124       NaN
1992-12-31  0.096678  0.098404       NaN
1993-12-31  0.401278  0.249947  0.000169
1994-12-31  0.799684  0.311359  0.001168

Data search

You can search the data using the search function. verbose is True by default, and if True, the top 4 data will be output to standard output.

>>> dataset = Quandl.search("Internet User", source="WORLDBANK", verbose=False)

If the number of results is large, the pages are divided, so it is necessary to specify the number of pages and execute repeatedly. Note that if there are too many pages, you may get caught in throttling.

>>> page = 0
>>> dataset = []
>>> import itertools as it
>>> for page in it.count():
...     d = Quandl.search("Internet User", page=page, source="WORLDBANK", verbose=False)
...     if not d:
...         break
...     dataset.extend(d)

It's basically the same as searching with a browser, but if you want to get the Quandl Code all at once, it may be easier to use the API.

Other

See the documentation for more details on other APIs.

See the API documentation for options that are not supported by the Python library. You can also use it by opening the URL directly using urllib2 etc.

reference

Recommended Posts

Get data from Quandl in Python
Get time series data from k-db.com in Python
Get Leap Motion data in Python.
Get data from GPS module at 10Hz in Python
Hit REST in Python to get data from New Relic
Get additional data in LDAP with python
Get exchange rates from open exchange rates in Python
[Note] Get data from PostgreSQL with Python
Get Google Fit API data in Python
Get Youtube data in Python using Youtube Data API
Get battery level from SwitchBot in Python
Get Precipitation Probability from XML in Python
Get metric history from MLflow in Python
Get date in Python
Get stock price data with Quandl API [Python]
Get only articles from web pages in Python
Get YouTube Comments in Python
Get structural data from CHEMBLID
Handle Ambient data in Python
Get last month in python
Display UTM-30LX data in Python
Get Youtube data with python
OCR from PDF in Python
Get Terminal size in Python
Explicitly get EOF in python
Get Evernote notes in Python
Get Japanese synonyms in Python
Receive dictionary data from a Python program in AppleScript
Get LEAD data using Marketo's REST API in Python
Get data from database via ODBC with Python (Access)
Generate Word Cloud from case law data in python3
Python: Exclude tags from html data
Get your heart rate from the fitbit API in Python!
Read Protocol Buffers data in Python3
Hit treasure data from Python Pandas
Get the desktop path in Python
Handle NetCDF format data in Python
[Python] Get economic data with DataReader
Get the script path in Python
Get the value while specifying the default value from dict in Python
Extract text from images in Python
Hashing data in R and Python
Get, post communication memo in Python
Get upcoming weather from python weather api
Get macro constants from C (++) header file (.h) in Python
Get data from analytics API with Google API Client for python
Get the desktop path in Python
Get the host name in Python
Get data from Twitter using Tweepy
Get started with Python in Blender
Get message from first offset with kafka consumer in python
Extract strings from files in Python
How to get a string from a command line argument in python
Get data from MySQL on a VPS with Python 3 and SQLAlchemy
Conditional element extraction from data frame: R is% in%, Python is .isin ()
Get html from element with Python selenium
Data input / output in Python (CSV, JSON)
Get Suica balance in Python (using libpafe)
Use PostgreSQL data type (jsonb) from Python
Get keystrokes from / dev / input (python evdev)
Python: Reading JSON data from web API