python pandas 读取execl指定类型插入Oracle 或mysql
1、pandas指定类型插入Oracle数据库
import pandas as pd import sqlalchemy.types as type from connet_ora import connet_oracle # 链接Oracle engine = connet_oracle() df = pd.read_excel('./gzyh/生产规则编号.xls',dtype=str) # data.to_csv("./data/df.csv") print(df.head()) # 空值处理 # df[df=='nan'] = None # df.fillna('',inplace=True) print(df.shape) data:pd.DataFrame = df.copy() # 指定字段类型插入 col_type:dict = {'SUB_FETR_ID':type.VARCHAR(11),'EXSQL':type.VARCHAR(2000)} data.to_sql('t1d_fetr_sql_20220629', con=engine,if_exists='replace',index=False,chunksize=1000,dtype=col_type)
自动化学习。