Last active
April 3, 2023 08:44
-
-
Save bruskiza/a70b09e63af33abed23ec23f540f697a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sqlalchemy import create_engine | |
def test_create_excel(): | |
# create some data | |
data = {'product_name': ['laptop', 'printer', 'tablet', 'desk', 'chair'], | |
'price': [1200, 150, 300, 450, 200] | |
} | |
# make it a data frame | |
df = pd.DataFrame(data) | |
# write it to excel | |
df.to_excel("file.xlsx") | |
def test_excel_to_sql(): | |
# create the engine to database | |
engine = create_engine('sqlite:///my_database.db') | |
# read the excel file | |
data = pd.read_excel("file.xlsx") | |
# drop it in the database | |
data.to_sql('file', con=engine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment