Python beginner here. I have a text file that is sorted into columns:
fields = line.split("\t")
I am trying to ask if any of the values in columns 3 to 23 are greater than 95. All the columns contain single floating numbers eg 94.522342 or 99.2321321. What I have so far seems not to be working:
if (int(fields(3:23)) >= 95):
I think the problem is with the (3:23) portion, when I am trying to ask to check each column.
Any help greatly appreciated,
Thank you!
There are two problems with your code: You are comparing a list to a number, which does not give a meaningful result. And you are using
int()to decode floating-point numbers – usefloat()instead:Note that this will examine the fourth column (index 3) up to the 23rd column (index 22). Adjust the slice as necessary.