python - Reading row data from CSV file -
i'm trying create program reads csv file, more row data (data in lines across)
sampledata.csv:
['time', 'date', 'color ', 'name'] ['1pm', '01-01-99', 'blue', 'jack'] ['2pm', '02-02-99', 'green', 'kevin'] ['3pm', '03-03-99', 'yellow', 'phil'] ['4pm', '04-04-99', 'white', 'alice'] ['5pm', '05-05-99', 'black', 'bob']
here code:
import csv open('sampledata.csv', 'r') csvfile : regnumber = input("what regnumber?") reader = csv.reader(csvfile, delimiter=',') row in reader: print(row) # here lies problem(python reading columnal data (data going down) instead of row(lines across) data#
the problem in reading columns (data going down). python reads columns instead.
output:
date 01-01-99 02-02-99 03-03-99 04-04-99 05-05-99
is 1 you're looking for?
import csv #ignore stupidity indentation , spaces# open('sampledata.csv', 'r') csvfile : regnumber = raw_input("enter time:") reader = csv.reader(csvfile) row in reader: if(row[0]==regnumber): print ', '.join(row) else: continue
the above code print values csv file row row.
Comments
Post a Comment