Manipulate query results

This section shows how to work with a query’s result so as to extract data in the form that is most convenient for your application.

Result as a list

By default, Driver.execute_query() returns an EagerResult object.

records, summary, keys = driver.execute_query(
    "MATCH (a:Person) RETURN a.name AS name, a.age AS age",
    database_="<database-name>",
)
for person in records:  (1)
    print(person)
    # person["name"] or person["age"] are also valid

# Some summary information  (2)
print("Query `{query}` returned {records_count} records in {time} ms.".format(
    query=summary.query, records_count=len(records),
    time=summary.result_available_after
))

print(f"Available keys are {keys}")  # ['name', 'age'] (3)
1 The result records come in a list.
2 A summary of execution, with metadata and information about the result.
3 The keys available in the returned rows.

Transform to Pandas DataFrame

The driver can transform the result into a Pandas DataFrame by setting result_transformer_=neo4j.Result.to_df. This method requires the pandas library is installed.