0

My CSV file has ~2.6 million records of transaction among different people. I am trying to make a graph from this file as: person having unique IDs as nodes and edges representing transaction between two people and want to fetch all possible cycles from the graph. I am trying to use networkx.simple_cycles(graph_name) to fetch all the cycles from this graph but getting this error:

    NetworkXNotImplemented                    Traceback (most recent call 
    last)
    <ipython-input-21-c36e4cd0e220> in <module>()
    ----> 1 nx.simple_cycles(Directed_G)

    <decorator-gen-215> in simple_cycles(G)

    ~\AppData\Local\Continuum\anaconda3\lib\site- 
     packages\networkx\utils\decorators.py in _not_implemented_for(f, *args, 
     **kwargs)
     64         if match:
     65             raise nx.NetworkXNotImplemented('not implemented for %s 
     type'%
     ---> 66                                             ' 
     '.join(graph_types))
     67         else:
     68             return f(*args,**kwargs)

     NetworkXNotImplemented: not implemented for undirected type

My Python code looks like this:

    import pandas as pd
    import time
    import networkx as nx
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns
    %matplotlib inline

    data=pd.read_csv(path/to/csv/file)
    Directed_G=nx.DiGraph()
    Directed_G=nx.from_pandas_dataframe(data, 'from', 'to')
    nx.simple_cycles(Directed_G)

My data looks something like this:

            from                to  
    0       000028c1f8598db 1a55bc3aab8562f     
    1       00003147f02a255 9c1f54d9859ce12     
    2       00003cdc5ed35a0 472f48d28903b43     
    3       00003cdc5ed35a0 5ab9e7e07978f9d 
    4       00003cdc5ed35a0 693452b7ae2fd0c

Can someone please help me with the error. Can there be some other way to find all the possible cycles from this graph?

4

1 回答 1

1

当你这样做时:

Directed_G=nx.from_pandas_dataframe(data, 'from', 'to')

它从 pandas 数据框创建一个图形,并将该结果分配给 name Directed_G。它不会先检查Directed_G以前的图形类型。因此,它使用默认类型(即Graph)创建了一个图,并且之前存储的图Directed_G被覆盖,丢失给了天空中的大型垃圾收集器。然后查找循环的命令会因为无法处理无向图而终止。

将可选参数添加create_using=DiGraph到对from_pandas_dataframe.

您应该知道,在最新版本的 networkxfrom_pandas_dataframe中已被删除:https ://networkx.github.io/documentation/networkx-2.0/release/release_2.0.html

以前,该函数from_pandas_dataframe假定数据帧具有类似边缘列表的结构,但会to_pandas_dataframe生成一个邻接矩阵。我们现在提供四个函数from_pandas_edgelistto_pandas_edgelistfrom_pandas_adjacencyto_pandas_adjacency

于 2018-05-10T19:57:28.490 回答