从python中的CSV列表中提取值

时间:2017-07-31 12:41:58

标签: python csv

我从CSV文件(CHFJPY15.csv)

导入了一个列表

但我在从列表中提取值并构建它们时已经完成了。

import csv
import operator
sample = open('CHFJPY15.csv', 'r')
csv1 = csv.reader(sample,delimiter=', ')
sort = sorted(csv1,key= operator.itemgetter(0=))
for eachline in sort:
     print eachline

列表的一部分:

['2017.07.21', '22:00', '117.602', '117.608', '117.577', '117.596',
'884'] ['2017.07.21', '22:15', '117.594', '117.604', '117.538',
'117.541', '804'] ['2017.07.21', '22:30', '117.541', '117.545',
'117.487', '117.497', '964'] ['2017.07.21', '22:45', '117.497',
'117.515', '117.474', '117.507', '1440'] ['2017.07.21', '23:00',
'117.506', '117.543', '117.498', '117.529', '1385'] ['2017.07.21',
'23:15', '117.528', '117.534', '117.478', '117.512', '718']
['2017.07.21', '23:30', '117.511', '117.530', '117.411', '117.422',
'1426']

1 个答案:

答案 0 :(得分:0)

如果你有.csv,你可以使用genfromtxt函数。它将返回一个numpy数组,你可以像矩阵一样访问每个位置,非常方便。