I have a function that works as follows to read a .csv file and store it in an array.
def read_csv(self, filename, delimiter = ',', quotechar = '"'):
reader = csv.reader(open(filename, 'rb'), delimiter = delimiter, quotechar = quotechar)
# read first line and extract its data
self.column_headings = np.array(next(reader))
# read subsequent lines
rows = []
for row in reader:
rows.append(row)
self.data = np.array(rows)
self.m, self.n = self.data.shape
I'm simply trying to read a .tsv file so that it will return in the same form. I have this so far :
traindata = np.array(p.read_table('train.tsv'))[:,2]
However, when I try to call :
m, n = traindata.data.shape
# Display
print m, n, traindata.column_headings
I get the error :
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-1f877ccb37b5> in <module>()
----> 1 m, n = traindata.data.shape
AttributeError: 'buffer' object has no attribute 'shape'
What is causing this issue and how can I fix it ?