infile=open(r'C:\Path\To\Input.csv','r') #opens a read only copy #get csv into array: lines=[] for line in infile: lines.append(line.split(',')) infile.close() toOut=[lines[0]] #start output with the header prevFC=lines[1][3] #start with first fc tempList=[] for line in lines[1:]: #skip header if line[0]=='\n' or line[0]=="(Newline)\n": continue fc=line[3] if prevFC!=fc: avg=sum(tempList)/float(len(tempList)) toOut.append(['','',str(avg),'\n']) toOut.append(['','','','\n']) #add blank line tempList=[] toOut.append(line) val=float(line[2]) tempList.append(val) prevFC=fc #add last average line: avg=sum(tempList)/float(len(tempList)) toOut.append(['','',str(avg),'\n']) toOut.append(['','','','\n']) #add blank line #build output: toOutCSV='' for line in toOut: toOutCSV+=','.join(line) #Write to output file: outfile=open(r'C:\Path\To\Output.csv','w') #opens a write copy (will overwrite output) outfile.write(toOutCSV) outfile.close()
with open("foo.csv", "r") as f: f.readline() # get rid of the first line # this section goes in a loop f.readline() #discard newline lineOne = f.readline() # first line with a value x = float(lineOne.split(",")[2]) lineTwo = f.readline() x += (float(lineTwo.split(",")[2]))/2 # this is your value # do something
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.