Python table function.
In this guide, we will learn how to query Pandas using the Python table function.
Setup
Let’s first create a virtual environment:ipython to run the commands in the rest of the guide, which you can launch by running:
Creating a Pandas DataFrame from a URL
We’re going to query some data from the StatsBomb GitHub repository. Let’s first import requests and pandas:match_id to that DataFrame:
Querying Pandas DataFrames
Next, let’s see how to query these DataFrames using chDB. We’ll import the library:Python table function:
matches_df, we could write the following:
events_df.
Joining Pandas DataFrames
We can also join DataFrames together in a query. For example, to get an overview of the match, we could write the following query:Populating a table from a DataFrame
We can also create and populate ClickHouse tables from DataFrames. If we want to create a table in chDB, we need to use the Stateful Session API. Let’s import the session module:events table based on events_df:
Joining a Pandas DataFrame and table
Finally, we can also update our join query to join thematches_df DataFrame with the statsbomb.events table: