Search code examples
python-2.7pandaspeewee

How to convert a select query into a pandas DataFrame using PeeWee


Using the PeeWee ORM I have the following query:

query = DataModel.select()where(DataModel.field == "value")

Is there any way to convert query into a pandas DataFrame without iterating over all the values? I'm looking for a more "Pythonic" way of doing this.


Solution

  • Assuming query is of type peewee.SelectQuery, you could do:

    df = pd.DataFrame(list(query.dicts()))
    

    EDIT: As Nicola points out below, you're now able to do pd.DataFrame(query.dicts()) directly.