Created
February 17, 2022 20:01
-
-
Save reuf/62dfd989ac9a8cf1664ee8cdc66e974d to your computer and use it in GitHub Desktop.
This file contains 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
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