如何将CSV文件的第一列中的所有值附加到数组上。
鉴于csv
Anas,5/1/2015,2.875
Jack,5/1/2015,33.925
Conk,5/1/2015,136.85
数组将是
['Anas', 'Jack', 'Conk']
如果我需要一个带有第二列值的单独数组,它也会是相同的代码吗?
这就是我试过的
for line in file:
Data=line.split(",")
FromFile=Data[0]
questions=FromFile.append(line)
答案 0 :(得分:0)
with open("example.csv") as f:
allData = [line.strip().split(",") for line in f]
firstColumn = [data[0] for data in allData]
secondColumn = [data[1] for data in allData]
thirdColumn = [data[2] for data in allData]