1
Hello, my friends
I am developing the code so that I can clean and organize the data (as shown above) and one of the best ways was to insert the data into a file CSV so that later I could return it in spreadsheet format, so I applied the following code:
import csv
with open('/content/Pasta2.csv', 'w') as out_file:
writer = csv.writer(out_file, delimiter=',',lineterminator='\n')
writer.writerow(('URL','Documento', 'Código CVM', 'Data de Referência', 'Status'))
writer.writerow([linha_1])
teste_02 = pd.read_csv('/content/Pasta2.csv')
teste_02
However, the return that I have is shown in the image below, the code simply takes the text that is inside the "line_1' and does not divide the cells, I would like to know which code I can implement to solve this problem, can help me?
Expected Result:
hello, Onilol I tried the way you said, but it didn’t work, the closest I could get was this way, it separated in the columns, but doesn’t break the lines: '' import csv with open('/content/Pasta2.csv', 'w') as out_file: Writer = csv.Writer(out_file, delimiter=',',lineterminator=' n') Writer.writerow(('URL','Document', 'CVM Code', 'Reference Date', 'Status')) Writer.writerow(linha_1.replace("',''').split(' ')) teste_02 = read._csv('/content/Pasta2.csv') teste_02
– Diego Provesi
Hmmm, take a look at module documentation
csv
then I remember that it has a way of mapping the headers and already printa everything cute.– Onilol
Oops, got it! I’ll post the answer below, thanks for the help, Onilol.
– Diego Provesi