DEV Community

Cover image for Read/Write data from/to SQLITE using Python Pandas
Muthu
Muthu

Posted on

Read/Write data from/to SQLITE using Python Pandas

PUSH EXCEL FILE TO SQLITE FILE

import pandas as pd
import sqlite3

EXCEL_FILE_NAME = 'source.xlsx'
DB_NAME = 'stage.db'

df= pd.read_excel(open(EXCEL_FILE_NAME , 'rb'),skiprows=3,index=False)

conn = sqlite3.connect(DB_NAME)
df.to_sql('source', conn)

Enter fullscreen mode Exit fullscreen mode

READ FROM SQLITE



import pandas as pd
import sqlite3

DB_NAME = 'stage.db'

conn = sqlite3.connect(DB_NAME)
sql_string = 'select * from source_tbl where id>10'
df = pd.read_sql(sql_string, conn)
print(df)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)