The following is a more efficient way, because it avoids creating the list and then pass it to the pandas dataframe. It also has the side benefit of preserving the order of the columns:
df = pd.read_sql(query.sql()[0], database.connection())
You need direct access to the peewee database
, for example, in the quickstart tutorial corresponds to:
db = SqliteDatabase('people.db')
Of course, you can also create your own connection to the database.
Drawback: you should be careful if you have repeated columns in the two tables, e.g. id
columns would appear twice. So make sure to correct those before continuing.
If you are using a peewee proxy
import peewee as pw;
database_proxy = pw.Proxy()
then the connection is here:
database_proxy.obj.connection()