import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://root:你的密码@localhost:3306/你的数据库名称')
con = engine.connect()
df.to_sql('example', con=engine, index=False, if_exists='replace')
con:数据库配置index:是否将df的index单独写到一列中if_exists: 三个模式:fail,若表存在,则不输出;replace:若表存在,覆盖原来表里的数据;append:若表存在,将数据写到原表的后面。默认为fail。
转载请注明原文地址:https://ipadbbs.8miu.com/read-17896.html