I'm trying to iterate over each cell in a CSV file, without any success. To simplify things, let say my csv file is a 3x3 matrix:
8.046875 10.4375 -0.625
0.171875 4.546875 1.953125
-4.890625 -3.703125 6.359375
Now, I'm iterating the cells with the following code:
import csv
class GetData:
def __init__(self, path):
self.path = path
def read_matrix(self):
with open(self.path, 'r') as matrix:
csv_reader = csv.reader(matrix, delimiter=',')
for cell in csv_reader:
cell = ', '.join(cell)
print(cell)
test = GetData('D:/testFile_0001.ascii.csv')
test.read_matrix()
If I run this code, it prints the matrix that shown above. When I'm changing to:
print(cell[0])
the output is:
8
0
-
My questions are: 1. why does it prints the first digit from the first column? 2. How can I print a specific cell from this matrix?
Thank you!