各位版上大神 大家好,
小弟我想將地端的一些EXCEL資料寫進我架設好的MySQL裡面,
遵循官方文件及網路上的資源嘗試利用python將這些資料用迴圈的方式直接寫進DB,
可是當執行的時候會出現以下錯誤訊息,
因此想跪求版上各位大神幫我看看我是不是有哪裡寫錯了呢????
AttributeError: 'Connection' object has no attribute 'connect'
Code
import pandas as pd, warnings, pymysql, os
from sqlalchemy import *
warnings.simplefilter("ignore")
user, pwd = "root", "root"
host, port, db = "127.0.0.1", 3306, "myDB"
dbConnection = create_engine("mysql+pymysql://{}:{}@{}/{}?charset=utf8".format(user, pwd, host, db), pool_recycle = port).connect()
path = "..\DATAFRAME"
folder = os.listdir(path)
for i in folder:
df = pd.read_excel("{}/{}".format(path, i))
df.to_sql(i.replace(".xlsx", ""), con = dbConnection, if_exists = "replace", index = False)
import pandas as pd, warnings, pymysql, os
from sqlalchemy import create_engine
warnings.simplefilter("ignore")
user, pwd = "root", "root"
host, port, db = "127.0.0.1", 3306, "myDB"
engine = create_engine("mysql+pymysql://{}:{}@{}/{}?charset=utf8".format(user, pwd, host, db), pool_recycle = port)
dbConnection = engine.connect()
path = "..\DATAFRAME"
folder = os.listdir(path)
for i in folder:
df = pd.read_excel("{}/{}".format(path, i))
df.to_sql(i.replace(".xlsx", ""), con = dbConnection, if_exists = "replace", index = False)