Skip to content

Instantly share code, notes, and snippets.

@partrita
Created June 6, 2025 02:02
Show Gist options
  • Save partrita/cef5efa0b388079f71418311ca8d9079 to your computer and use it in GitHub Desktop.
Save partrita/cef5efa0b388079f71418311ca8d9079 to your computer and use it in GitHub Desktop.
duckdb 가 그렇게 좋다던데
import duckdb
import os
# 데이터베이스 파일 경로 설정
db_file_path = '../data/my_database.duckdb'
# 파일 기반 데이터베이스에 연결
con = duckdb.connect(database=db_file_path)
# CSV 파일 불러오기
result = con.execute("SELECT * FROM read_csv_auto('../data/flights.csv')").fetchdf()
print(result)
# 연결 닫기 (모든 변경사항은 my_database.duckdb 파일에 자동으로 저장됨)
con.close()
# 나중에 다시 연결하여 데이터 확인
print(f"\n'{db_file_path}' 파일을 다시 열어 데이터 확인:")
con_reopen = duckdb.connect(database=db_file_path)
print(result)
con_reopen.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment