AttributeError: module 'networkx' has no attribute 'from_pandas_dataframe'

前端 未结 3 336
名媛妹妹
名媛妹妹 2021-01-07 16:40

I have networkx v. 2.1. to make it work w/ pandas dataframe, i tried following:

  • installed via pip3, this did not work generated
相关标签:
3条回答
  • 2021-01-07 16:59

    This solution helps as well:

    G = nx.DiGraph()
    G.add_weighted_edges_from([tuple(x) for x in x.values])
    nx.info(G)
    
    
    'Name: \nType: DiGraph\nNumber of nodes: 5713\nNumber of edges: 5000\nAverage in degree:   0.8752\nAverage out degree:   0.8752'
    
    0 讨论(0)
  • 2021-01-07 17:03

    A simple graph:

    import pandas as pd
    import numpy as np
    import networkx as nx
    import matplotlib.pyplot as plt
    
    # Build a dataframe with 4 connections
    df = pd.DataFrame({'from': \['A', 'B', 'C', 'A'\], 'to': \['D', 'A', 'E', 'C'\]})
    
    # Build your graph
    G = nx.from_pandas_edgelist(df, 'from', 'to')
    
    # Plot it
    nx.draw(G, with_labels=True)
    plt.show()
    

    0 讨论(0)
  • 2021-01-07 17:08

    In networkx 2.0 from_pandas_dataframe has been removed.

    Instead you can use from_pandas_edgelist.

    Then you'll have:

    g_data=G=nx.from_pandas_edgelist(x, 1, 2, edge_attr=True)
    
    0 讨论(0)
提交回复
热议问题