- import cStringIO
- output = cStringIO.StringIO()
- # ignore the index
- df_a.to_csv(output, sep='\t',index = False, header = False)
- output.getvalue()
- # jump to start of stream
- output.seek(0)
- connection = engine.raw_connection() #engine 是 from sqlalchemy import create_engine
- cursor = connection.cursor()
- # null value become ''
- cursor.copy_from(output,table_name,null='')
- connection.commit()
- cursor.close()
dataframe写入postgresql数据库中
最新推荐文章于 2024-08-03 15:52:30 发布