Sei sulla pagina 1di 1

import csv; import networkx as nx; import string

readerNum = csv.reader(open('C:\data\wdc\pass_2008_CSV\pass_2008_CSV.csv', 'rb')


, 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

Potrebbero piacerti anche