https://www.jianshu.com/p/7cb41e880b30

遍历

groupsdf.groups

for group,df in groupsdf:
   print(group,df)
from sqlalchemy import create_engine
import pandas as pd 

#获得数据库链接
con=create_engine("mysql+pymysql://root:abc123456@zhansansan.com:3306/test?charset=utf8")

#获取所有sheets的名字
a=pd.ExcelFile('bb.xlsx')
sheets=a.sheet_names


for sheet in sheets:
    print(sheet)
    df=pd.read_excel('bb.xlsx',sheet_name=sheets[1])
    
    df=df.ix[:,:15]   
    
    df["序号"]=df["序号"].fillna(method='pad').astype(int)
    df["数1"]=df["数1"].fillna(method='pad')

    df.dropna(how="all",subset=["数据", "共享"],inplace=True)
    

    df.to_sql("tableA",con,index=False,if_exists="append")
 engine = create_engine("mysql://scott:tiger@hostname/dbname",
                                encoding='latin1', echo=True)
import pandas as pd
import MySQLdb
import MySQLdb.cursors
config = {
     'host': 'localhost',
     'port': 3036,
     'user': 'root',
     'passwd': '111111',
     'db': 'mysql',
     'charset': 'utf8',
     'cursorclass': MySQLdb.cursors.DictCursor
}
con=MySQLdb.connect(**config)
sql="select host,user from mysql.user"
pd.read_sql_query(sql=sql,con=con)

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注