Skip to content

Instantly share code, notes, and snippets.

@reuf
Created February 17, 2022 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reuf/62dfd989ac9a8cf1664ee8cdc66e974d to your computer and use it in GitHub Desktop.
Save reuf/62dfd989ac9a8cf1664ee8cdc66e974d to your computer and use it in GitHub Desktop.
from sqlalchemy import create_engine
import pymysql
import pandas as pd
table = pd.read_excel("Sarajevo.xlsx")
table2 = pd.read_excel("SrebrenicaAll.xlsx")
tableName = "knjiga_mrtvih_sarajevo"
tableName2 = "knjiga_mrtvih_srebrenica"
dataFrame = pd.DataFrame(data=table)
dataFrame2 = pd.DataFrame(data=table2)
sqlEngine = create_engine('mysql+pymysql://root:Root1234@127.0.0.1/knjigamrtvih', pool_recycle=3600)
dbConnection = sqlEngine.connect()
try:
# frame = dataFrame.to_sql(tableName, dbConnection, if_exists='fail');
frame = dataFrame2.to_sql(tableName2, dbConnection, if_exists='fail');
except ValueError as vx:
print(vx)
except Exception as ex:
print(ex)
else:
print("Table %s created successfully."%tableName);
print("Table %s created successfully." %tableName2);
finally:
dbConnection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment