I have a bunch of csv files containing temporary data and numbers, I wrote a function to return the first number of a number below the threshold (x) as follows:
def bounce(tickList,x): n = 0 for i in tickList: if float(i[1]) < x: return n break n += 1
except that when I execute the bounce function execution loop as follows:
for i in os.listdir(resultDir): if "csv" in i: csvFile = resultDir+i print csvFile with open(csvFile, 'rb') as f: reader = csv.reader(f) tickList = [] for line in reader: tickList.append(line) print bounce(tickList,5)
it continues to return zero (even if the first value is higher ).
Where am I going wrong?
Here is an example of one of the csv files:
1373289767.454535,9.9 1373289769.728528,9.9 1373289771.817576,9.9 1373289773.813036,11.7 1373289775.810985,11.7 1373289777.769641,11.7 1373289779.783134,12.2 1373289781.774255,11.8 1373289783.799892,12.0 1373289785.812967,11.4 1373289787.816991,11.4 1373289789.790835,11.3 1373289791.811245,10.9 1373289793.880356,10.8 1373289795.846866,10.7 1373289797.847552,10.6 1373289799.858929,10.6
Thanks in advance.
EDIT after comments
Here is a new feature:
def bounce(tickList,x): n = 0 for i in tickList: if float(i[1]) < x: return nn += 1
If I print float (i [1]), it will return the correct numbers to call the correct files.
SECOND EDIT
found the problem, the "level" that I fed was actually str , not int , thanks to everyone who looked and helped.