Saturday 15 May 2010

Finding same values in a row of csv in python -



Finding same values in a row of csv in python -

i have code looks numbers within csv file within 1.0 decimal places of each other in same row. although, when run it, prints everything. not rows have status want i.e. values 2nd , 3rd column within 1.0 of each other. want run code , have display, first column (the time @ recorded or improve yet column number), 2nd , 3rd column because should within 1.0 of each other. info file looks like:

time chan1 chan2 04:07.0 52.31515503 16.49450684 04:07.1 23.55230713 62.48802185 04:08.0 46.06217957 24.94955444 04:08.0 41.72077942 31.32516479 04:08.0 19.80723572 25.73182678

here's code:

import numpy np matplotlib import * pylab import * filename = raw_input("enter file name: ") + '.csv' filepath = '/home/david/desktop/' + filename info = np.genfromtxt(filepath, delimiter=',', dtype=float) first=[row[0] row in data] rownum1=[row[1] row in data] rownum2=[row[2] row in data] row in data: if ((abs(row[1]-row[2]) <= 1.0)): print("the values in row 0 1 , 2, within 1.0 of each other.", first, rownum1, rownum2)

this output:

26.3460998535, 44.587371826199998, 42.610519409200002, 24.7272491455, 89.397918701199998, 25.479614257800002, 30.991180419900001, 25.676086425800001

but want output:

4:09.0, 23.456, 22.5

you can this:

data = np.genfromtxt(filepath, names=true, dtype=none) idx = np.abs(data['chan1'] - data['chan2'])<1 print data[idx]

python csv

No comments:

Post a Comment