LoginSignup
1
1

More than 5 years have passed since last update.

Jupyter NotebookでSQLiteDBから選択したデータをヘッダ付きで表示するための備忘録

Last updated at Posted at 2018-08-02

SQLite3でselectしたデータをData Frameとして表示する

ライブラリのインポート

import pandas as pd
import sqlite3

sqlite3の使い方

データベースとの接続を行う

conn = sqlite3.connection("sample.db")
cur = conn.cursor

カーソルオブジェクトの作成

cur.execute("select * from TABLE;")
pd.DataFrame(cur.fetchall(), columns=[description[0] for description in cur.description()])

cur.description()によってテーブルのヘッダー部分を取得できるため、それをDataFrameのcolumnsに当ててあげれば良い。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1