to_pandas_edgelist#

to_pandas_edgelist(G, source='source', target='target', nodelist=None, dtype=None, edge_key=None)[来源]#

将图的边列表作为 Pandas DataFrame 返回。

参数:
**G**

用于构建 Pandas DataFrame 的 NetworkX 图。

**source**str 或 int,可选

源节点(对于有向图)的有效列名(字符串或整数)。

**target**str 或 int,可选

目标节点(对于有向图)的有效列名(字符串或整数)。

**nodelist**list,可选

仅使用 nodelist 中指定的节点

**dtype**dtype,默认 None

用于创建 DataFrame。强制的数据类型。仅允许单个 dtype。如果为 None,则推断。

**edge_key**str、int 或 None,可选 (默认 None)

边键(对于多重图)的有效列名(字符串或整数)。如果为 None,则边键不存储在 DataFrame 中。

返回:
**df**Pandas DataFrame

图边列表

示例

>>> G = nx.Graph(
...     [
...         ("A", "B", {"cost": 1, "weight": 7}),
...         ("C", "E", {"cost": 9, "weight": 10}),
...     ]
... )
>>> df = nx.to_pandas_edgelist(G, nodelist=["A", "C"])
>>> df[["source", "target", "cost", "weight"]]
  source target  cost  weight
0      A      B     1       7
1      C      E     9      10
>>> G = nx.MultiGraph([("A", "B", {"cost": 1}), ("A", "B", {"cost": 9})])
>>> df = nx.to_pandas_edgelist(G, nodelist=["A", "C"], edge_key="ekey")
>>> df[["source", "target", "cost", "ekey"]]
  source target  cost  ekey
0      A      B     1     0
1      A      B     9     1