Requirement: Import the Excel file into the database for storage.
Note: All symbols in the Excel table are all in English!!!
Demo file:
Implementation code:
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)
Running result:
Reference: Save Excel into database