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

前端 未结 3 337
名媛妹妹
名媛妹妹 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 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()
    

提交回复
热议问题