Search code examples
pandasgoogle-colaboratorynetworkxnetwork-analysis

How to create a network graph from a dataset using colab?


I successfully uploaded the edges file of my dataset but how can I create the network graph?

the uploaded data


Solution

  • Here's networkx:

    import networkx as nx
    import pandas as pd
    
    # note that your file doesn't have column names
    # passing `names` to label the columns
    df = pd.read_csv('file.csv', names=['a','b'])
    
    # don't worry about `source` and `target`
    G = nx.from_pandas_edgelist(df, source='a', target='b')
    

    Then G is a bi-directional graph instance.