DuckDB 2 · From Python
Query a pandas DataFrame
Use a DataFrame variable as a table in SQL, with no copying step.
import pandas as pd
df = pd.DataFrame({"city": ["Rome", "Oslo", "Rome"], "sales": [10, 20, 30]})
duckdb.sql("SELECT city, sum(sales) AS total FROM df GROUP BY city ORDER BY total DESC").df()
Official DuckDB 2 documentation