如何读取包含此contrait的.csv文件特定项?

时间:2015-04-11 23:56:43

标签: python python-2.7 csv

我有一个非常大的文件:

SynsetTerms,PosScore,NegScore
a prueba de,0.208333333333,0.0833333333333
a reacción,0,0.0625
a salvo,0.1875,0.0625
a través de,0.1875,0.0
a ultranza,0.125,0.0

我想在列表中放入SynsetTerms>所有POsScore 0。如何使用csv python模块完成此任务?

1 个答案:

答案 0 :(得分:2)

这很简单,只需解析文件并解压缩三个值,如下所示:

with open('text.csv') as text:
    # iterate the list except for the title line and grab desired items
    data = [a for a, b, c in list(csv.reader(text))[1:] if float(b) > 0]