---
title: "Querying Pandas DataFrames with ClickHouse"
description: "chDB, an embedded Python library built on the ClickHouse engine, can run SQL directly against Pandas DataFrames through the chdb.dataframe module."
url: "https://swe.quest/articles/querying-pandas-dataframes-with-clickhouse-f6443dd364e0e7c9"
canonical: "https://clickhouse.com/blog/querying-pandas-dataframes"
source: "ClickHouse"
published: "2023-11-15"
difficulty: "medium"
kind: "How-to"
reading_minutes: 4
tags: ["python","analytics","sql"]
---

# Querying Pandas DataFrames with ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-11-15, 4 min read, How-to. Original: [https://clickhouse.com/blog/querying-pandas-dataframes](https://clickhouse.com/blog/querying-pandas-dataframes)

## Summary

chDB, an embedded Python library built on the ClickHouse engine, can run SQL directly against Pandas DataFrames through the chdb.dataframe module. DataFrames are passed as named parameters and referenced in SQL as \_\_name\_\_. The walkthrough uses Kaggle Canadian house-price data to show aggregation with GROUP BY ALL, joining two DataFrames, re-querying the resulting chDB Table via \_\_table\_\_, and converting results back with to\_pandas(). It needs pandas and pyarrow installed, and string columns come back as bytes, so filters must compare against values like b"Ontario".

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Python](https://swe.quest/tags/python.md) (Languages)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- Pandas DataFrames
- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

chDB, ClickHouse, Pandas, PyArrow

## Related posts

- [How we made querying Pandas DataFrames with chDB 87x faster](https://swe.quest/articles/how-we-made-querying-pandas-dataframes-with-chdb-87x-faster-1ee5b7d8017e769d.md): ClickHouse · 2024-08-29 · Medium · 8 min read · Python, Performance engineering, Query engines, Analytics & OLAP, C & C++
  chDB, the in-process embedded ClickHouse, sped up SQL queries over Pandas DataFrames 87x by replacing its original Parquet serialize/deserialize round-trip through file descriptors with a native Python table engine that reads Python objects directly.
- [Welcome, chDB](https://swe.quest/articles/welcome-chdb-80fea87c647d8ab8.md): ClickHouse · 2023-08-31 · Medium · 7 min read · Analytics & OLAP, Python, Databases, Open source
  chDB is a community-built embedded SQL OLAP engine that packages ClickHouse as an in-process Python module, similar in spirit to DuckDB, for local analytics, ETL and exploration without running a server.
- [Announcing chDB 4: write Pandas, run ClickHouse, now on Hex](https://swe.quest/articles/announcing-chdb-4-write-pandas-run-clickhouse-now-on-hex-3e3042b3b93d1f1e.md): ClickHouse · 2026-03-11 · Medium · 11 min read · Analytics & OLAP, Query engines, Python, Performance engineering
  chDB 4 adds DataStore, a Pandas-compatible API that records operations lazily as a chain of LazyOps, then compiles them into ClickHouse SQL with filter pushdown, column pruning and limit propagation, executing in-process on the ClickHouse engine.
- [An introduction to Ibis](https://swe.quest/articles/an-introduction-to-ibis-8a6a34b40efccef2.md): ClickHouse · 2024-08-05 · Medium · 8 min read · Python, Analytics & OLAP, SQL
  Ibis is an open-source Python dataframe library that compiles lazy, composable relational expressions to SQL and runs them on 20+ backends, including ClickHouse.
- [The Journey to Zero-Copy: How chDB Became the Fastest SQL Engine on Pandas DataFrame](https://swe.quest/articles/the-journey-to-zero-copy-how-chdb-became-the-fastest-sql-engine-on-pandas-b4ab858523515f13.md): ClickHouse · 2026-01-09 · Medium · 8 min read · Python, Performance engineering, Analytics & OLAP, Query engines
  chDB, ClickHouse embedded as a Python library, removed the four serialization steps that made every v1 query take over 100ms by reading Pandas DataFrames in place.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
