from sqlqlchemy import create_engine
def getData(path):
data = pd.read_excel(path)
return data
def writeData(data):
conn = create_engine(
"mysql+pymysql://root:keijay@localhost:3306/db_name?charset=utf8")
pd.io.sql.to_sql(data, "table_name", con = conn,index = False)
if __name__ == "__main__":
path = "E:\datasets\test.xlsx"
data = getData(path)
writeData(data)
遇到问题:
1、写入完成后有告警:
解决方法:
pip install mysql-connect-python -i https://pypi.douban.com/simple
将:
conn = create_engine(
"mysql+pymysql ://root:keijay@localhost:3306/db_name?charset=utf8")
修改为:
conn = create_engine(
" mysql+mysqlconnector ://root:keijay@localhost/test_python?charset=utf8")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)