python fetchall()转化为数据框,将查询结果转换为Python中的DataFrame

I am trying to perform manipulation on the result from a query using psycog2. Thus I have to covert result into pandas DataFrame. But when i use the following code and print, only the columns name are printed not the rows. I used 'pd.DataFrame.from_records' too but that did not work.

import psycopg2

import pandas as pd

import numpy as np

conn_string = "Connect_Info"

conn = psycopg2.connect(conn_string)

cursor = conn.cursor()

cursor.execute(query)

rows=pd.DataFrame(cursor.fetchall(),columns=['page_num','Frequency'])

for row in rows:

print row

conn.commit();

conn.close();

The result of cursor.fetchall() -

(1L, 90990L)

(3L, 6532L)

(2L, 5614L)

(4L, 4016L)

(5L, 2098L)

(6L, 1651L)

(7L

你可能感兴趣的:(python)