2
I am trying to remove empty lines from a csv document:
Document:
phrase,
.,pt
.,en
.,en
.,it
.,es
.,pt
.,pt
.,es
.,pt
.,pt
"it’s not Expensive",en
"casi 50 euros la alfombra es cara",
" the price should go down!! " ,en
" new prices please ! ?? " ,en
My script:
import csv
import string
with open ("test.csv", "r") as f:
csvfile = csv.reader(f, delimiter = ',')
for line in csvfile:
if line[1] == 'pt':
frases = " ".join(line[0].lower().split())
removePunct = "".join(word for word in mails if word not in string.punctuation)
noEmptyLines = " ".join(lines for lines in removePunct if len(lines) != 0)
print (noEmptyLines)
The expected result:
the price should go down
new prices please
My result:
n o v o s p r e ç o s p o r f a v o r
Have you tried . strip() ?
– FourZeroFive