Skip to main content

Transform the data with Pandas

You can fetch results of any SQL query as a dataframe. If the destination is supporting that natively (i.e. BigQuery and DuckDB), dlt uses the native method. Thanks to that, reading dataframes may be really fast! The example below reads GitHub reactions data from the issues table and counts reaction types.

pipeline = dlt.pipeline(
with pipeline.sql_client() as client:
with client.execute_query(
'SELECT "reactions__+1", "reactions__-1", reactions__laugh, reactions__hooray, reactions__rocket FROM issues'
) as table:
# calling `df` on a cursor, returns the data as a data frame
reactions = table.df()
counts = reactions.sum(0).sort_values(0, ascending=False)

The df method above returns all the data in the cursor as data frame. You can also fetch data in chunks by passing chunk_size argument to the df method.

Once your data is in a Pandas dataframe, you can transform it as needed.

Other transforming tools

If you want to transform the data before loading, you can use Python. If you want to transform the data after loading, you can use Pandas or one of the following:

  1. dbt. (recommended)
  2. dlt SQL client.

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!


Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.