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,787
  • 2
  • 20
  • 46

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,156
  • 8
  • 15