i have file containing results (integers) in several columns (tab separated), 2 lines of text @ beginning telling me file's contents , 2 lines @ end telling me if file's contents complete.
i have script order file according value of first column extend skips first two, , last 2 lines of file while printing out ordered first column. how so?
this script have:
file_name = "output1.dat" new_file_name = "sorted_"+file_name data = csv.reader(open(file_name),delimiter='\t') sortedlist = sorted(data, key=lambda x:int(x[0])) #now write sorte result new csv file open(new_file_name, "wb") f: filewriter = csv.writer(f, delimiter=',') row in sortedlist: filewriter.writerow(row)
it gets tripped lines of text don't contain columns.
this should skip first 2 , last 2 lines:
sortedlist = sorted(list(data)[2:-2], key=lambda x:int(x[0]))
write first column:
filewriter.writerow(row[:1])
full script:
file_name = "output1.dat" new_file_name = "sorted_"+file_name data = csv.reader(open(file_name),delimiter='\t') sortedlist = sorted(list(data)[2:-2], key=lambda x:int(x[0])) #now write sorte result new csv file open(new_file_name, "wb") f: filewriter = csv.writer(f, delimiter=',') row in sortedlist: filewriter.writerow(row[:1])
Comments
Post a Comment