Thursday, 15 March 2012

Identifying the highest number in a row with Python -


I have data in three columns, so I'm trying to identify the biggest value in each row ( 1, 2,3) And also ignore the rows where the highest value is more than once, the script below will recognize the highest value in each row but I am unable to fix the other two issues. Any advice would be greatly appreciated! <3> 3 3 3 3 3 3 3 3 3 3 3 Data = open ('file.csv', 'r') rows = [] For data in line: line = [Int (each) line split ()] .append (line) data.close () for column = zip (* rows) for index, enumerate (rows) in column: print max (column)

Since all of your rows are in a list, so you loop on that list and you To find information that you want Use some built-in:

  gvalues ​​= [] for lines in rows: highest = maximum (line) match = row.count (highest) position = row.index (highest) If matching == 1: gvalues.append ((highest, position)) and: gvalues.append ((none, none))  

Once it's finished, your There will be a list gvalues ​​ containing the highest value, position toplevel for each line in it, none, any Will not Tion where more than one highest .

For example you will provide it

(none, none),

No comments:

Post a Comment