Column names for SQL-df extracted.

Hi,

I am able to retrieve the data from DB with below code, but its column names is of the digits from 0 onwards. How do I automatically retrieve its original column names?

Code:

import psycopg2
import numpy as np
import pandas as pd

conn = psycopg2.connect(database="DBname", user="username", password="password***", host="12.12.345.678", port="5432")

cursor = conn.cursor()
cursor.execute("SELECT * from daily_consumption order by date_consumption desc limit 1000")
rows=cursor.fetchall()
consumption_df = pd.DataFrame(rows)

a=consumption_df.head(10)

print(a)

See output here: https://imgur.com/Mqwt0A1

Thanks.

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like Follow
  • 8 mths agoLast active
  • 227Views
  • 1 Following

Create A New Discussion

Share your thoughts