Skip to content

Instantly share code, notes, and snippets.

@RCura
Created February 1, 2012 15:59
Show Gist options
  • Save RCura/1717699 to your computer and use it in GitHub Desktop.
Save RCura/1717699 to your computer and use it in GitHub Desktop.
script de correction des tableaux
import csv
import os
print "debut"
for nbReseau in range(8):
for nbSimulation in range(10):
print "reseau " + str(nbReseau + 1) + " / Simulation : " + str(nbSimulation + 1)
inFilePath = "/home/administrateur/experiences/reseau_" + str(nbReseau + 1) + "-exp_" + str(nbSimulation + 1) + "_links-traffic.csv"
inFile = open(inFilePath)
inCsv = csv.reader(inFile)
outFilePath = "/home/administrateur/experiences/reseau_" + str(nbReseau + 1) + "-exp_" + str(nbSimulation + 1) + "_links-traffic_OK.csv"
outFile = open(outFilePath, 'w+')
outCsv = csv.writer(outFile, quoting=csv.QUOTE_NONNUMERIC)
for row in inCsv:
rowlength = len(row)
if rowlength >= 22:
outCsv.writerow(row[0:21])
elif rowlength < 22:
rowName = list()
rowName.append(row[0])
if rowlength == 2:
rowsFull = list()
rowsFull.append(row[1])
else:
rowsFull = row[1:(rowlength - 1)]
missingRowsNb = 22 - rowlength
myNAList = list()
for i in range(missingRowsNb):
myNAList.append("NA")
newRow = rowName + myNAList + rowsFull
outCsv.writerow(newRow)
inFile.close()
outFile.close()
os.remove(inFilePath)
os.rename(outFilePath, inFilePath)
print "fini"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment