【发布时间】:2021-08-23 12:22:02
【问题描述】:
我正在使用 Python 中的 psycopg2 连接到 QuestDB 并运行 select * from my_table,但列名是序号:
import psycopg2
import pandas as pd
dataframe = pd.DataFrame()
try:
connection = psycopg2.connect(user="myuser",
password="mypassword",
host="127.0.0.1",
port="8812",
database="qdb")
cursor = connection.cursor()
cursor.execute("SELECT * FROM my_table")
dataframe = pd.DataFrame(cursor.fetchall())
except (Exception, psycopg2.Error) as error:
print("Error while connecting to QuestDB", error)
finally:
if (connection):
cursor.close()
connection.close()
print("QuestDB connection closed")
print(dataframe)
没有列名的行如下所示:
0 1 2
0 2021-08-23 12:15:43.582771 100 1
1 2021-08-23 12:15:46.529379 1 2
2 2021-08-23 12:15:46.656823 1 2
3 2021-08-23 12:15:46.662040 1 2
4 2021-08-23 12:15:46.805505 1 2
5 2021-08-23 12:15:46.807359 1 2
6 2021-08-23 12:15:48.631560 1 2
7 2021-08-23 12:16:08.120285 6 3
【问题讨论】:
标签: python pandas dataframe questdb