vrproject

Complex Network Analysis VR-project
git clone git://popovic.xyz/vrproject.git
Log | Files | Refs | LICENSE

csv_to_network.py (743B)


      1 #/usr/bin/env python3.10
      2 
      3 import pandas as pd
      4 import numpy as np
      5 import networkx as nx
      6 
      7 def get_graph(data:pd.DataFrame, cut:int, direction=""):
      8     DG = nx.from_pandas_edgelist(data, source='package', target='requirement',\
      9                                  create_using=nx.DiGraph())
     10     DG.remove_nodes_from(['.', 'NaN', np.nan, ''])
     11     if direction == "":
     12         to_remove = [n[0] for n in DG.degree() if n[1] < cut]
     13         DG.remove_nodes_from(to_remove)
     14     elif direction == "in":
     15         to_remove = [n[0] for n in DG.in_degree() if n[1] < cut]
     16         DG.remove_nodes_from(to_remove)
     17     elif direction == "out":
     18         to_remove = [n[0] for n in DG.in_degree() if n[1] < cut]
     19         DG.remove_nodes_from(to_remove)
     20     return DG