dataframe写入postgresql数据库中

来源:互联网 发布:c读取excel单元格数据 编辑:程序博客网 时间:2024/06/15 01:20
  1. import cStringIO  
  2.   
  3. output = cStringIO.StringIO()  
  4. # ignore the index  
  5. df_a.to_csv(output, sep='\t',index = False, header = False)  
  6. output.getvalue()  
  7. # jump to start of stream  
  8. output.seek(0)  
  9.   
  10. connection = engine.raw_connection() #engine 是 from sqlalchemy import create_engine  
  11. cursor = connection.cursor()  
  12. # null value become ''  
  13. cursor.copy_from(output,table_name,null='')  
  14. connection.commit()  
  15. cursor.close() 
阅读全文
0 0