0 valutazioniIl 0% ha trovato utile questo documento (0 voti)
140 visualizzazioni1 pagina
Python code (using NetworkX API) to build an undirected, weighted graph from the following publicly available source data: http://data.octo.dc.gov/feeds/pass/archive/pass_2008_CSV.zip
Python code (using NetworkX API) to build an undirected, weighted graph from the following publicly available source data: http://data.octo.dc.gov/feeds/pass/archive/pass_2008_CSV.zip
Copyright:
Attribution Non-Commercial (BY-NC)
Formati disponibili
Scarica in formato TXT, PDF, TXT o leggi online su Scribd
Python code (using NetworkX API) to build an undirected, weighted graph from the following publicly available source data: http://data.octo.dc.gov/feeds/pass/archive/pass_2008_CSV.zip
Copyright:
Attribution Non-Commercial (BY-NC)
Formati disponibili
Scarica in formato TXT, PDF, TXT o leggi online su Scribd
, delimiter=',', quotechar='"') readerNum.next() #skips the header row in the csv file #calculate the min/max contract value minVal = 9999999999999 maxVal = -999999999999 for nums in readerNum : strnum = string.replace(nums[3],"$","") nr = string.atof(strnum) if nr < minVal : minVal = nr if nr > maxVal : maxVal = nr denom = maxVal - minVal #should close the readerNum at this point # open the file again reader = csv.reader(open('C:\data\wdc\pass_2008_CSV\pass_2008_CSV.csv', 'rb'), d elimiter=',', quotechar='"') head = reader.next() #skips the header row in the csv file G = nx.Graph() for dat in reader : #iterate over the reader strnum = string.replace(dat[3],"$","") #remove the '$' nr = string.atof(strnum) #convert the numeric str ing to a number w = ((nr - minVal) / denom) #normalize the weight [0 ,1] G.add_edge(dat[1],dat[5]) #add edge to the graph G[dat[1]][dat[5]]['weight']=w #add weight to the edge