Pandas로 내보내기

Pandas로 내보내기

DuckDB 쿼리 결과를 파이썬에서 곧바로 Pandas DataFrame으로 받고 싶을 때가 많죠. 이번 페이지에서는 그 변환을 담당하는 df() 함수를 소개합니다.

출처: 공식문서

쿼리 결과는 df() 함수를 사용해 Pandas DataFrame으로 변환할 수 있어요.

import duckdb

# read the result of an arbitrary SQL query to a Pandas DataFrame
results = duckdb.sql("SELECT 42").df()
results
   42
0  42

이렇게 하면 duckdb.sql(...)의 결과를 바로 Pandas DataFrame 객체로 받을 수 있어서, 이후에는 익숙한 Pandas API로 데이터를 다룰 수 있게 됩니다.

더 알아보기 (Learn more)