用pandas來讀取sqlite資料檔案

Steven Wang
1 min readMay 11, 2019

--

Pandas提供了兩個函式,均可以讀取字尾為“.sqlite”資料檔案的資訊。

read_sql()

read_sql_query()

import pandas as pd
with sqlite3.connect('test_database.sqlite') as con:
# read_sql_query和read_sql都能通過SQL語句從資料庫檔案中獲取資料資訊
df = pd.read_sql_query("SELECT * FROM test_table", con=con)
# df = pd.read_sql("SELECT * FROM test_table", con=con)
print(df.shape)
print(df.dtypes)
print(df.head())

--

--

Steven Wang
Steven Wang

No responses yet