要件:保存のためにExcelファイルをデータベースにインポートします。
注:Excelテーブルのすべての記号はすべて英語です!!!
デモファイル:
実装コード:
import pymysql
import pandas as pd
from sqlalchemy import create_engine
file = r'./data.xlsx'
df = pd.read_excel(file)
engine = create_engine("mysql+pymysql://root:root@localhost:3306/python",encoding='utf-8')
df.to_sql('testexcel',con=engine,if_exists='replace',index=False)
実行結果:
参照:Excelをデータベースに保存