我遇到了一个问题,似乎答案很容易解释。我正在使用代码从具有行和列的 csv 文件中进行改进:
import csv
import os
import glob
import numpy as np
def get_data(filename):
with open(filename, 'r') as f:
reader = csv.reader(f)
return list(reader)
all_data = []
path=raw_input('What is the directory?')
for infile in glob.glob(os.path.join(path, '*.csv')):
all_data.extend(get_data(infile))
a = np.array(all_data)
col=a[:,[0,1]]
print col
但是结果会产生前两行而不是列?