Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bruskiza/a70b09e63af33abed23ec23f540f697a to your computer and use it in GitHub Desktop.
Save bruskiza/a70b09e63af33abed23ec23f540f697a to your computer and use it in GitHub Desktop.
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