yield value from csv file python

Solutions on MaxInterview for yield value from csv file python by the best coders in the world

showing results for - "yield value from csv file python"
Vincent
22 Jan 2018
1import csv
2import numpy as np
3
4def getData(filename1, filename2):
5    with open(filename1, "rb") as csv1, open(filename2, "rb") as csv2:
6        reader1 = csv.reader(csv1)
7        reader2 = csv.reader(csv2)
8        for row1, row2 in zip(reader1, reader2):
9            yield (np.array(row1, dtype=np.float),
10                   np.array(row2, dtype=np.float)) 
11                # This will give arrays of floats, for other types change dtype
12
13for tup in getData("file1", "file2"):
14    print(tup)