Home >Database >Mysql Tutorial >How to Convert SQL Query Results into a Pandas DataFrame?
Converting SQL Query Results to pandas DataFrames
In this scenario, you aim to retrieve data from an SQL database using a query and store it in a pandas data structure. The question revolves around the data type of the query result and how to convert it to a DataFrame.
Understanding the Query Result
The sample query you provided performs various summations on fields from the table "daily_report_cooked." The result is a collection of rows, each containing the aggregate values for a particular campaign.
Converting to a pandas DataFrame
To convert the query result to a DataFrame, follow these steps:
The following code snippet demonstrates the conversion process:
from pandas import DataFrame df = DataFrame(resoverall.fetchall()) df.columns = resoverall.keys()
Now, the variable df represents a pandas DataFrame containing the query results. It provides a structured representation of the data, enabling further analysis and manipulation using pandas' extensive functionality.
The above is the detailed content of How to Convert SQL Query Results into a Pandas DataFrame?. For more information, please follow other related articles on the PHP Chinese website!