Skip to content

query(query: str)

Marcel Ferrari edited this page Feb 10, 2023 · 4 revisions

The query function is used to execute a query that returns table data. It takes a single argument, the query string, and returns the result as a pandas DataFrame.

Warning: executing SQL statements that do not return any data raises an error.

Function

def query(query: str) -> pd.DataFrame:
    """
    Execute query that returns table data.

    Parameters:
    - query (str): SQL query to be executed

    Returns:
    - pd.DataFrame: result of the query
    """

Example:

# Connect to the database
db = PandaSQLiteDB("example.sql")

# Execute a query to get all data from the "my_table" table
result = db.query("SELECT * FROM my_table")

print(result.head())