to_pandas_edgelist#

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

以熊猫数据帧的形式返回图形边缘列表。

参数
G图表

用于构建Pandas DataFrame的网络X图。

source字符串或int,可选

源节点的有效列名(字符串或整数)(用于定向情况)。

target字符串或int,可选

目标节点的有效列名(字符串或整数)(用于定向情况)。

nodelist列表,可选

仅使用节点列表中指定的节点

dtype数据类型,默认为无

用于创建DataFrame。要强制的数据类型。只允许使用单一数据类型。如果没有,则推断。

order

函数中错误地包含了未使用的参数。

2.6 版后已移除: 此功能已弃用,将在NetworkX v3.0中删除。

edge_key字符串、整型或无,可选(默认值=无)

边关键帧的有效列名(字符串或整数)(对于多重图情况)。如果无,则边关键点不会存储在DataFrame中。

返回
df熊猫数据框

图形边列表

实例

>>> 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