cugraph.experimental.PropertyGraph.annotate_dataframe#

PropertyGraph.annotate_dataframe(df, G, edge_vertex_col_names)[source]#

Add properties to df that represent the vertices and edges in graph G.

Parameters:
dfcudf.DataFrame or pandas.DataFrame

A DataFrame containing edges identified by edge_vertex_col_names which will have properties for those edges added to it.

Gcugraph.Graph (or subclass of) instance.

Graph containing the edges specified in df. The Graph instance must have been generated from a prior call to extract_subgraph() in order to have the edge meta-data used to look up the correct properties.

edge_vertex_col_namestuple of strings

The column names in df that represent the source and destination vertices, used for identifying edges.

Returns:
A copy of df with additional columns corresponding to properties for
the edge in the row.

Examples

>>> import cudf
>>> from cugraph.experimental import PropertyGraph
>>> df = cudf.DataFrame(columns=["src", "dst", "some_property"],
...                      data=[(99, 22, "a"),
...                            (98, 34, "b"),
...                            (97, 56, "c"),
...                            (96, 88, "d"),
...                           ])
>>> pG = PropertyGraph()
>>> pG.add_edge_data(df, type_name="etype", vertex_col_names=("src", "dst"))
>>> G = pG.extract_subgraph(create_using=cugraph.Graph(directed=True))
>>> # Represents results of an algorithm run on the graph returning a dataframe
>>> algo_result = cudf.DataFrame({"from":df.src,
...                                "to":df.dst,
...                                "result": range(len(df.src))})
>>> algo_result2 = pG.annotate_dataframe(algo_result,
...                                       G,
...                                       edge_vertex_col_names=("from", "to"))
>>> print (algo_result2.sort_index(axis=1))
_EDGE_ID_ _TYPE_  from  result some_property  to
0          0  etype    99       0             a  22
1          1  etype    98       1             b  34
2          2  etype    97       2             c  56
3          3  etype    96       3             d  88