Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. id Date Col_1 Col_2 Col_3
  2. 26 2012-10-18 X 25.7 True
  3. 42 2012-10-19 Y -12.4 False
  4. 63 2012-10-20 Z 5.73 True
  5.  
  6. In [437]: data.to_sql('data', engine)
  7.  
  8. In [438]: data.to_sql('data_chunked', engine, chunksize=1000)
  9.  
  10. for row in data.iterrows():
  11.  
  12. import psycopg2
  13.  
  14. # Fill in the blanks for the conn object
  15. conn = psycopg2.connect(user = 'user',
  16. password = 'password',
  17. host = 'host',
  18. dbname = 'db',
  19. port = 666)
  20. cursor = conn.cursor()
  21.  
  22. args_str = b','.join(cursor.mogrify("(%s,%s,...)", x) for x in tuple(map(tuple,np_data)))
  23. cursor.execute("insert into table (a,b,...) VALUES "+args_str.decode("utf-8"))
  24.  
  25. cursor.close()
  26. flexprobi_conn.commit()
  27. flexprobi_conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement