Skip to content

Pandas and Opteryx Integration

This short guide demonstrates how to integrate Pandas and Opteryx, showing you how to query a Pandas dataframe with Opteryx and how to return Pandas dataframe from Opteryx.

Installation

Install Opteryx and Pandas.

$ pip install opteryx
$ pip install pandas

Pandas to Opteryx

Opteryx can natively query Pandas DataFrames by registering the DataFrame as a data source.

import opteryx
import pandas

# Create the DataFrame
data = {
    "Name": ["Huey", "Dewey", "Louie"],
    "Age": [12, 12, 12],
    "Favorite Color": ["Red", "Blue", "Green"],
}
df = pandas.DataFrame(data)

# Register as a data source
opteryx.register_df("nephews", df)

results = opteryx.query("SELECT * FROM nephews")

Opteryx to Pandas

Opteryx can output results as Pandas DataFrames using the .pandas() result-conversion method.

import opteryx

dataframe = opteryx.query("SELECT * FROM $planets").pandas()