pandas supports several data types, from CSV to JSON to HTML. Here, we will use the export capabilities of Neo4j in CSV files.
We learned, in a previous section, how to run a Cypher query from Python and get the results. The most interesting function for us now is the result.data() function, which returns a list of records, where each record is a dictionary. It is interesting because pandas does have a simple method to create a DataFrame from this structure – using the pd.DataFrame.from_records function.
First, let's check an example and define a list of records, as follows:
list_of_records = [
{"a": 1, "b": 11},
{"a": 2, "b": 22},
{"a": 3, "b": 33},
]
Creating a DataFrame from this list is as simple as the following:
pd.DataFrame.from_records(list_of_records)
It creates a DataFrame with two columns, named a and b, and three rows indexed from 0 to 2:
a b
0 1 11
1 2 22
2...