当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python cugraph.structure.convert_matrix.from_pandas_edgelist用法及代码示例


用法:

cugraph.structure.convert_matrix.from_pandas_edgelist(df, source='source', destination='destination', edge_attr=None, create_using=<class 'cugraph.structure.graph_classes.Graph'>, renumber=True)

从边列表初始化一个图。在已初始化的 Graph 对象上调用此方法是错误的。源参数是源列名,目标参数是目标列名。

默认情况下,启用重新编号以将源顶点和目标顶点映射到 [0, V) 范围内的索引,其中 V 是顶点数。如果输入顶点是 [0, V) 范围内的单列整数,则可以禁用重新编号,并且将使用原始的外部顶点 ID。

如果存在权重,edge_attr 参数是权重列名称。

参数

dfpandas.DataFrame

包含边信息的 DataFrame

sourcestr 或array-like,可选(默认='source')

源列名或列名数组

destinationstr 或array-like,可选(默认='destination')

目标列名或列名数组

edge_attrstr 或无,可选(默认=无)

权重列名称。

renumber布尔,可选(默认=真)

指示是否对源顶点 ID 和目标顶点 ID 重新编号。

create_using: cugraph.DiGraph or cugraph.Graph, optional (default=Graph)

指示是创建有向图还是无向图

返回

Gcugraph.DiGraph 或 cugraph.Graph

包含来自 pandas 边列表的边的图

例子

>>> #  Download dataset from
>>> #  https://github.com/rapidsai/cugraph/datasets/...
>>> df = pd.read_csv(datasets_path / 'karate.csv', delimiter=' ',
...                  header=None, names=["0", "1", "2"],
...                  dtype={"0": "int32", "1": "int32", "2": "float32"})
>>> G = cugraph.Graph()
>>> G.from_pandas_edgelist(df, source='0', destination='1',
...                        edge_attr='2', renumber=False)

相关用法


注:本文由纯净天空筛选整理自rapids.ai大神的英文原创作品 cugraph.structure.convert_matrix.from_pandas_edgelist。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。