@@ -7,6 +7,65 @@ In this section we will cover how to import data from `Pandas DataFrames <https:
77`Neo4j Graph Data Science <https://neo4j.com/docs/graph-data-science/current/ >`_.
88
99
10+ Pandas DataFrames
11+ -----------------
12+
13+ The ``neo4j-viz `` library provides a convenience method for importing data from Pandas ``DataFrame``s.
14+ It requires and additional dependency to be installed, which you can do by running:
15+
16+ .. code-block:: bash
17+
18+ pip install neo4j-viz[pandas]
19+
20+ Once you have installed the additional dependency, you can use the :doc:`from_gds <./api-reference/from_pandas>` method
21+ to import pandas ``DataFrame``s.
22+
23+ The ``from_dfs `` method takes two mandatory positional parameters:
24+
25+ * A Pandas ``DataFrame ``, or iterable (eg. list) of ``DataFrame``s representing the nodes of the graph.
26+ The rows of the ``DataFrame``(s) should represent the individual nodes, and the columns should represent the node
27+ IDs and properties. The columns map directly to fields on :doc:`Nodes <./api-reference/node>`, and as such
28+ should follow the same naming conventions.
29+ * A Pandas ``DataFrame ``, or iterable (eg. list) of ``DataFrame``s representing the relationships of the graph.
30+ The rows of the ``DataFrame``(s) should represent the individual relationships, and the columns should represent the
31+ relationship IDs and properties. The columns map directly to fields on
32+ :doc:`Relationships <./api-reference/relationship>`, and as such should follow the same naming conventions.
33+
34+ ``from_dfs `` also takes an optional property, ``node_radius_min_max ``, can be used (and is used by default) to scale
35+ the node sizes for the visualization.
36+ It is a tuple of two floats, representing the radii (sizes) in pixels of the smallest and largest nodes respectively in
37+ the visualization.
38+ This can be useful if node sizes vary a lot, or are all very small or very big.
39+
40+
41+ Example
42+ ~~~~~~~
43+
44+ In this small example, we import a tiny toy graph representing a social network from two Pandas ``DataFrame``s.
45+ As we can see the column names of the ``DataFrame``s map directly to the fields of :doc:`Nodes <./api-reference/node>`
46+ and :d
47+
48+ .. code-block:: python
49+ from pandas import DataFrame
50+ from neo4j_viz.pandas import from_dfs
51+
52+ nodes = DataFrame({
53+ "id": [1, 2, 3],
54+ "caption": ["Alice", "Bob", "Charlie"],
55+ "size": [20, 10, 10],
56+ })
57+ relationships = DataFrame({
58+ "source": [1, 2],
59+ "target": [2, 3],
60+ "caption": ["LIKES", "KNOWS"],
61+ })
62+
63+ VG = from_dfs(nodes, relationships)
64+
65+ For another example of the ``from_dfs `` importer in action, see the
66+ :doc: `Visualizing Snowflake Tables tutorial <./tutorials/snowpark-nvl-example >`.
67+
68+
1069Neo4j Graph Data Science (GDS) library
1170--------------------------------------
1271
@@ -22,6 +81,7 @@ Once you have installed the additional dependency, you can use the :doc:`from_gd
2281to import projections from the GDS library.
2382
2483The ``from_dfs `` method takes two mandatory positional parameters:
84+
2585* An initialized ``GraphDataScience `` object for the connection to the GDS instance, and
2686* A ``Graph `` representing the projection that one wants to import.
2787
@@ -74,8 +134,3 @@ We use the "pagerank" property to determine the size of the nodes, and the "comp
74134
75135 Please see the :doc: `Visualizing Neo4j Graph Data Science (GDS) Graphs tutorial <./tutorials/gds-nvl-example >` for a
76136more extensive example.
77-
78-
79- Pandas DataFrames
80- -----------------
81-
0 commit comments