adding simple mathematical operation to python script -


i have program operates on csv file create output looks this:

724, 2 724, 1 725, 3 725, 3 726, 1 726, 0 

i modify script simple math operations such render output:

724, 1.5 725, 3 726, 0.5 

the script i'm using here:

lines=open("1.txt",'r').read().splitlines() l in lines:     data = l.split('"overall evaluation:')     if len(data) == 2:         print(data[0] + ", " + data[1]) 

how add simple averaging , slicing operation pipeline?

i guess need create temporary variable, should outside loop iterates on lines?

maybe this:

lines=open("easychairdata.csv",'r').read().splitlines()  l in lines:     data = l.split('"overall evaluation:')      submission_number_repo = data[0]      if len(data) == 2:         print(data[0] + ", " + data[1])          if submission_number_repo != data[0]             submission_number_repo = data[0] 

edit

the function simple average

you can use dictionary map key total , count , print it:

map = {} lines=open("1.txt",'r').read().splitlines() l in lines:     data = l.split('"overall evaluation:')     if len(data) == 2:         if data[0] not in map.keys():             map[data[0]] = (0,0)         map[data[0]] = (map[data[0]][0]+int(data[1]) , map[data[0]][1]+1) x, y in map.items():     print(str(x) + ", " + str(y[0]/y[1])) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -