Write fast pandas dataframe to postgres
问题 I wonder of the fastest way to write data from pandas DataFrame to table in postges DB. 1) I've tried pandas.to_sql , but for some reason it takes entity to copy data, 2) besides I've tried following: import io f = io.StringIO() pd.DataFrame({'a':[1,2], 'b':[3,4]}).to_csv(f) cursor = conn.cursor() cursor.execute('create table bbbb (a int, b int);COMMIT; ') cursor.copy_from(f, 'bbbb', columns=('a', 'b'), sep=',') cursor.execute("select * from bbbb;") a = cursor.fetchall() print(a) cursor.close