Python: deleting rows in a text file

Posted by Jenny on Stack Overflow See other posts from Stack Overflow or by Jenny
Published on 2010-04-12T16:05:50Z Indexed on 2010/04/12 16:13 UTC
Read the original article Hit count: 321

Filed under:
|
|

A sample of the following text file i have is:

> 1 -4.6    -4.6    -7.6
> 
> 2 -1.7    -3.8    -3.1
> 
> 3 -1.6    -1.6    -3.1

the data is separated by tabs in the text file and the first column indicates the position.

I need to iterate through every value in the text file apart from column 0 and find the lowest value.

once the lowest value has been found that value needs to be written to a new text file along with the column name and position. Column 0 has the name "position" Column 1 "fifteen", column 2 "sixteen" and column 3 "seventeen"

for example the lowest value in the above data is "-7.6" and is in column 3 which has the name "seventeen". Therefore "7.6", "seventeen" and its position value which in this case is 1 need to be written to the new text file.

I then need a number of rows deleted from the above text file.

E.G. the lowest value above is "-7.6" and is found at position "1" and is found in column 3 which as the name "seventeen". I therefore need seventeen rows deleted from the text file starting from and including position 1

so the the column in which the lowest value is found denotes the amount of rows that needs to be deleted and the position it is found at states the start point of the deletion

© Stack Overflow or respective owner

Related posts about python

Related posts about textfiles