Database / DuckDB Interview questions
What is the Python API for DuckDB used for?
DuckDB's Python API, installed via pip install duckdb, lets Python code execute SQL queries directly against DuckDB and exchange data with common Python data tools with minimal overhead.
import duckdb import pandas as pd df = pd.read_csv("sales.csv") result = duckdb.sql("SELECT category, SUM(amount) FROM df GROUP BY category").df()
A distinctive feature shown above is that DuckDB can query a Pandas DataFrame (df) directly by name inside SQL, as if it were a table, without an explicit conversion or copy step, thanks to zero-copy integration with Pandas and Apache Arrow. This lets a data scientist mix SQL and Python/Pandas code fluidly within the same workflow, using whichever is more convenient for a given step, rather than needing to fully commit to one tool or the other.
More Related questions...