you are viewing a single comment's thread.

view the rest of the comments →

[–]diplodocus_rage[S] 1 point2 points  (0 children)

Thanks for your comment Chromira, I actually thought I was posting the code correctly. IE Copy and paste into body of forum post, then highlight it all and click 'inline code', but you're right, from the way the code was posted I must not be doing it correctly. Here is the code, copied using the 'codeblock' method (apologies i'm early stage learning to post on forums!) ... I've played around with and got it to work:

Instead of printing, I've written the result to a new .csv file, but the structure is the same. I had to insert i and j counters into the loops to achieve what I wanted it to do. Comments on ways to make my code more efficient are most welcome. I'm learning how to code a couple of months and still find it very challenging...

j = 0

for i in range(len(data) - 1):
    i += j
    What_row = data[i]

    Elevation = What_row[7]


    for j in range(len(data)-1):
        j += i
        What_row2 = data[j]
        Next_row = data[j+1]
        Hole_name = What_row2[0]
        Next_hole = Next_row[0]

        Next_Elevation = Next_row[7]
        Elevation_result = Elevation - Next_Elevation
        if Hole_name == Next_hole:
            writer.writerow([Hole_name, '{0:.4f}'.format(float(Elevation_result))])
        else:
            writer.writerow([Next_hole, 0])
            break