DEV Community

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

Posted on

6

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay