Ask Your Question
3

What is the method to retrieve a particular sheet from an xlsx file in sqlite3 using pandas?

asked 2023-02-04 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-08-20 00:00:00 +0000

huitzilopochtli gravatar image

First, import the necessary libraries:

import sqlite3
import pandas as pd

Next, open a connection to the SQLite database:

conn = sqlite3.connect('database.db')

Then, read the Excel file using pandas and store it in a pandas DataFrame:

df = pd.read_excel('file.xlsx', sheet_name='sheet_name')

Finally, write the pandas DataFrame to the SQLite database:

df.to_sql(name='table_name', con=conn)

Note that you will need to replace 'database.db', 'file.xlsx', 'sheetname', and 'tablename' with the appropriate values for your specific situation.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-04 11:00:00 +0000

Seen: 10 times

Last updated: Aug 20 '22