skwoi
skwoi

Reputation: 919

How to read a .csv file specific items that hold this contrait?

I have a pretty large file like this:

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

I would like to place in a list all the SynsetTerms that has POsScore > 0 . How can I aproach this task with the csv python's module?.

Upvotes: 0

Views: 22

Answers (1)

Malik Brahimi
Malik Brahimi

Reputation: 16711

That is very simple, just parse the file and unpack the three values like so:

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]

Upvotes: 2

Related Questions