Search code examples
pandasdataframecsvnetworkxsocial-networking

how to convert csv file in proper format so that it can be used in networkx


i have the list of nodes but I don't have the list of edges which is essential for graph but there is relationship b/w nodes through patient id and provider id how to convert csv in proper format so the id column in this image represent nodes but I need edge list those nodes that have common provider and patient id will form edge how to convert this csv file in proper format


Solution

  • In networkx, for the following:

    edges = dataframe.groupby('PATIENTID')['Id'].apply(list)  
    

    This works for me and I got the list of nodes against each patient id.