[Tutor] How to change the values in python code?

samira khoda samiraeastcoast at gmail.com
Wed Nov 2 15:39:12 EDT 2022


Hi

Could you please help me to understand why the code below does not work? I
am trying to read a txt.file line by line that has integer timestamp
values, the last number should be compared to the previous number.

And then split it where the value of the last is less than previous. But
when I run the code prints 0 for previous in each line which technically
says should not be split anywhere. I did a manual check up and I know there
are various spots that the split should happen.

How can I make the value of the previous update to the value of the
previous timestamp and not stay zero for every line?

Thanks in advance

Sam

Import pandas as pd
previous=0
i=0
data=open('time-.txt', mode="r")

for line in data:

    x=line.split(", ")
    last=int(x[7])

if last < previous :
    print("split here"+i)
    previous=last
    i=i+1

 #end the loop


More information about the Tutor mailing list