Jeferson S Jeferson S -4 years ago 51
Python Question

Processing text in csv document

I'm starting some text analysis on some csv documents. However my csv document has several sentences with few words which do not interest me, so I wanted to create a python code that analyzed this csv document and left only the sentences that contain more than 5 words for my analysis, however I do not I know where to start making my code and would like some help.

example:

Input document
enter image description here

Output document
enter image description here

Answer Source

This should work (with Python 3.5):

lines = []
finalLines = []
toRemove = ['a', 'in', 'the']

with open('export.csv') as f:
    lines.append(f.readlines())

for line in lines:
    temp = list(csv.reader(line))
    sentence = ''
    for word in temp[0][0].split():
        if (word not in toRemove):
            sentence = sentence + ' ' + word
    finalLines.append(sentence.strip())

print(finalLines)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download