I have been trying to do the following in a long csv file with three columns:
for every row, getting the max and min of the entries of the previous 250 rows. The data is like this - column 1 is an index (1-5300), column 2 is where the data is and column 3 is another one, but not used here. This is the code I have till now. Note that 'i' is the row index which looks at column 1. Column 2 is where the data is stored (i.e. the data whose max and min I want).
The problem I have is that the csv.reader starts at the end of the file always and throws the whole algorithm out of the window. Don't know what I am doing wrong. Please help
max1 = 0
min1 = 1000000
i = 3476
f1= open('PUT/PUT_SELLING.csv')
file_reader = csv.reader(f1)
for col in file_reader:
serial = int(col[0])
if serial <i-250:
spyy = float(col[1])
print spyy
for j in range(0,250):
spyy = float(col[1])
max1 = max(max1,spyy)
min1 = min(min1,spyy)
file_reader.next()
#print spyy
f1.close()
print 'max =' +str(max1) + 'min = ' + str(min1)