Data Commons Pandas API

The Data Commons Pandas API is a superset of the Data Commons Python API: all functions from the Python API are also accessible from the Pandas API, and supplemental functions help with directly creating pandas objects using data from the Data Commons knowledge graph for common pandas use cases. Please see the Data Commons API Overview for more details on the design and structure of the API.

Before proceeding, make sure you have followed the setup instructions below.

Getting Started

To get started using the Pandas API:

  • Install the API using pip.
  • (Optional) Create an API key and enable the Data Commons API.
  • Begin developing with the Pandas API

Installing the Pandas API

First, install the datacommons_pandas package through pip.

$ pip install datacommons_pandas

For more information about installing pip and setting up other parts of your Python development environment, please refer to the Python Development Environment Setup Guide for Google Cloud Platform.

Creating an API Key (Optional)

If you would like to provide an API key, follow the steps in the API setup guide. Data Commons does not charge users, but uses the API key for understanding API usage.

With the API key created and Data Commons API activated, we can now get started using the pandas API. There are two ways to provide your key to the pandas API package.

  1. You can set the API key by calling datacommons_pandas.set_api_key. Start by importing datacommons_pandas, then set the API key like so.

    import datacommons_pandas as dcpd

    This will create an environment variable in your Python runtime called DC_API_KEY holding your key. Your key will then be used whenever the package sends a request to the Data Commons graph.

  2. You can export an environment variable in your shell like so.

    export DC_API_KEY='YOUR-API-KEY'

    After you’ve exported the variable, you can start using the Data Commons package.

    import datacommons_pandas as dcpd

    This route is particularly useful if you are building applications that depend on this API, and are deploying them to hosting services.

Using the Pandas API

You are ready to go! From here you can view our tutorials on how to use the API to perform certain tasks, or see a full list of functions, classes and methods available for use in the sidebar.