I would like to convert the psycopg2 DictRow request to a pandas dataframe, but pandas keeps complaining:
curs = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) curs.execute("SELECT * FROM mytable") data = curs.fetchall() print type(data) print pd.DataFrame(list(data))
However, I always get an error, although I specifically passed list
<type 'list'> TypeError: Expected list, got DictRow
The result will be the same if I do pd.DataFrame(data) Can someone help me do this work?
It would be nice if the file system column names worked (i.e. DictRow extracts and passed them to the dataframe).
Update:
Since I need to process the data, I would like to use the data from the psycopg2 request as is, and not under pandas , for example. read_sql_query .
n1000 source share