Connect from Python
Connect to Queria datasets from the duckdb package and pull data into a pandas DataFrame
This example attaches a DuckLake catalog with the duckdb package and receives the results as a pandas DataFrame. We pull the top 10 prefectures by total population from the e-Stat government statistics data.
import duckdb
conn = duckdb.connect()
conn.execute("INSTALL ducklake; LOAD ducklake;")
conn.execute("""
ATTACH 'ducklake:https://data.queria.io/e_stat/ducklake.duckdb'
AS e_stat (READ_ONLY)
""")
df = conn.execute("""
SELECT DISTINCT area_name, value AS population
FROM e_stat.ssds.a_pref_population
WHERE item_name = 'A1101_総人口'
AND year = 2024
AND area_name != '全国'
ORDER BY value DESC
LIMIT 10
""").fetchdf()
print(df.head())
Besides fetchdf() for a pandas DataFrame, you can use fetch_arrow_table() to receive an Apache Arrow table. From there it’s a short step to bar charts and maps with matplotlib or Plotly.
