how to use pandas.io.sql.read_frame?

I have python 2.7, and pandas 0.7.0, and I'm trying to query MySQL. When I do the query, the records in python are a bunch of tuples. I'm trying to convert them to a DataFrame, but not having much luck.

I've tried with pandas.io.sql.read_frame(), which is supposed to return the result set as a DataFrame. However, when I run it, it gives me an error that it got a type tuple when it expected a list.

Another option would be iterating through the results a few times, to get the column names, have several Series, then put those Series into a DataFrame. But, this seems like it would be the slow way.

Code:
import pandas as pd
import pd.io.sql as psql
import MySQLdb as db

conn = db.Connection( // connection info)
query = 'select * from crappo'
df = psql.read_frame(query, conn, 'ID') // tried with and without index column

this results in:

TypeError: Argument 'rows' has incorrect type (expected list, got tuple)

I've looked for documentation, but could not find any. Any ideas, is there something simple I've missed? thanks
 
If anyone was wondering about the original question, I found a way to do this - use MySQLdb to get a cursor (instead of pandas), fetch all into a tuple, then cast that as a list when creating the new DataFrame:

my_DF = DataFrame(data=list(tupleFromCursor), columns=columnsFromCursor)

list(tupleFromCursor) got it to work.
 
Quote from zedDoubleNaught:

use MySQLdb to get a cursor (instead of pandas), fetch all into a tuple, then cast that as a list when creating the new DataFrame:

Thanks. Useful to know.
 
Back
Top