I'm having a difficulty in the cell delimiter of the CSV file, when I command the save the edited file in CSV % with% delimiter by default is escritor.writerow([linhas])
, plus I need change to ,
because when I open the file in Excel , it does not recognize the breaking of the cells with ;
, so it's all in one column.
My code is like this:
import csv
coluna_Heading = 0
coluna_Number = 1
with open("testeIfHeading00.csv", "r") as arquivo_lido, open("saida.csv", "w", newline= "") as arquivo_criado:
#def o leitor CSV do arquivo
leitor = csv.reader(arquivo_lido, delimiter=';')
#def o escritor CSV do arquivo
escritor = csv.writer(arquivo_criado, delimiter=';')
#percorre as linhas do arquivo a ser lido
separatec = " "
for linhas in leitor:
if (len(linhas[coluna_Number]) == 1) or len(linhas[coluna_Number]) <= 2:
separatec = linhas[coluna_Heading]
linhas.append(separatec)
print(linhas)
escritor.writerow([linhas])