Text Processing in csv file

0

I have a database with more than a thousand reviews (text) in a csv file, however I need only texts that contain more than 5 words to be in my file. The problem is to make a code that scrolls the entire document line by line and leave only opinions that have more than 5 words, I have already researched some libraries and I have not had success in this implementation.

I'm using this code to read the file:

import csv
lines = []
finalLines = []

 with open('aborto.csv') as csvfile:
   readerCSV = csv.reader(csvfile, delimiter=',')
   print(readerCSV)

 for row in readerCSV:
    print(row) 

Entry:      Exit:  

    
asked by anonymous 14.06.2017 / 01:38

1 answer

1

Basically you need to fix the indentations in your code. Here's an example already using the CSV writing process:

import csv

# Abre o arquivo de saída para escrita:
with open("data.csv", 'r') as file_read, open('output.csv', 'w') as file_write:

    # Define o leitor CSV do arquivo:
    reader = csv.reader(file_read, delimiter=' ')

    # Define o escritor CSV do arquivo:
    writer = csv.writer(file_write, delimiter=' ')

    # Percorre as linhas do arquivo de entrada:
    for row in reader:

        # Verifica se o tamanho da linha é maior que o desejado:
        if len(row) > 5:

            # Escreve a linha no arquivo de saída:
            writer.writerow(row)
    
14.06.2017 / 02:01