def read_csv(filename, skip_lines=0):
csvfile = file(filename, 'rb')
reader = csv.reader(csvfile)
data = np.empty(0, dtype=object)
last_count = np.NAN
for line in reader:
if skip_lines > 0:
skip_lines = skip_lines - 1
continue
if data.size > 0:
if len(line) != last_count:
raise Exception('unequal columes found')
data = np.c_[data, line]
last_count = len(line)
else:
data = np.array(line, dtype=object)
data = data.reshape(len(data), 1)
last_count = len(line)
csvfile.close()
return data.T
评论列表
文章目录