You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/asciidoc/pythonclient/python-client-graph-object.adoc
+53-3Lines changed: 53 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,9 @@ Additionally, the `Graph` objects have convenience methods allowing for inspecti
11
11
include::python-client-gds-object.adoc[]
12
12
13
13
14
-
== Constructing a graph object
14
+
== Projecting a graph object
15
15
16
-
There are several ways of constructing a graph object.
16
+
There are several ways of projecting a graph object.
17
17
The simplest way is to do a <<graph-project-native-syntax, native projection>>:
18
18
19
19
[source,python]
@@ -41,14 +41,64 @@ To get a graph object that represents a graph that has already been projected in
41
41
G = gds.graph.get("my-graph")
42
42
----
43
43
44
-
In addition to those aforementioned there are three more methods that construct graph objects:
44
+
In addition to those aforementioned there are three more methods that create graph objects:
45
45
46
46
* `gds.graph.project.cypher`
47
47
* `gds.beta.graph.subgraph`
48
48
* `gds.beta.graph.generate`
49
49
50
50
Their Cypher signatures map to Python in much the same way as `gds.graph.project` above.
51
51
52
+
[.enterprise-edition]
53
+
== Constructing a graph
54
+
55
+
Instead of projecting a graph from the Neo4j database it is also possible to construct new graphs using pandas `DataFrames` from the client.
56
+
57
+
NOTE: To use this feature the <<installation-apache-arrow, Arrow Flight Server>> needs to be enabled.
58
+
59
+
[source,python]
60
+
----
61
+
nodes = pandas.DataFrame(
62
+
"nodeId": [0, 1, 2, 3],
63
+
"label": ["A", "B", "C", "A"],
64
+
"prop1": [42, 1337, 8, 0],
65
+
"otherProperty": [0.1, 0.2, 0.3, 0.4]
66
+
)
67
+
68
+
relationships = pandas.DataFrame(
69
+
"sourceId": [0, 1, 2, 3],
70
+
"targetId": [1, 2, 3, 0],
71
+
"type": ["REL", "REL", "REL", "REL"],
72
+
"weight": [0.0, 0.0, 0.1, 42.0]
73
+
)
74
+
75
+
G = gds.alpha.graph.construct(
76
+
"my-graph", # Graph name
77
+
nodes, # One or more dataframes containing node data
78
+
relationships # One or more dataframes containing relationship data
79
+
)
80
+
----
81
+
82
+
The above example creates a simple graph using one node and one relationship `DataFrame`.
83
+
The created graph is equivalent to a graph created by the following Cypher query:
84
+
85
+
[source, cypher]
86
+
----
87
+
CREATE
88
+
(a:A {prop1: 42, otherProperty: 0.1),
89
+
(b:B {prop1: 1337, otherProperty: 0.2),
90
+
(c:C {prop1: 8, otherProperty: 0.3),
91
+
(d:A {prop1: 0, otherProperty: 0.4),
92
+
(a)-[:REL {weight: 0.0}]->(b),
93
+
(b)-[:REL {weight: 0.0}]->(c),
94
+
(c)-[:REL {weight: 0.1}]->(d),
95
+
(d)-[:REL {weight: 42.0}]->(a),
96
+
----
97
+
98
+
It is possible to supply more than one data frame, both for nodes and relationships.
99
+
If multiple node dataframes are used, they need to contain distinct node ids across all node data frames.
100
+
The supported format for the node data frames is described in <<arrow-node-columns, Arrow node schema>> and the format for the relationship data frames is described in <<arrow-relationship-columns, Arrow relationship schema>>.
0 commit comments