0

For now my code looks like this:

conn = psycopg2.connect("dbname=monty user=postgres host=localhost password=postgres")
cur = conn.cursor()
cur.execute("SELECT * FROM binance.zrxeth_ob_indicators;")
for row in cur:
  df = pd.DataFrame(row,columns=['timestamp', 'topAsk', 'topBid', 'CPA', 'midprice', 'CPB', 'spread', 'CPA%', 'CPB%'])

But the data are not added to the dataframe, it just creates a new one? Any idea on how to append to the existing same DataFrame? Thanks!

Viktor.w
  • 1,397
  • 1
  • 13
  • 38

1 Answers1

0

Have you tried

df=pd.read_sql_query(“””select * from table “””, conn)

It will read all the the query results directly into a dataframe

Bruno Carballo
  • 1,064
  • 6
  • 14