Mar-24-2021, 10:55 PM
If i just copy some of your data,then doing some stuff to get it in a list data structure.
You can append to list so get similar structure,then it easy to write to csv.
You can append to list so get similar structure,then it easy to write to csv.
import csv data = '''\ 23/03/2021 09:09 50 18 34 1 23/03/2021 09:09 50 18 34 1 23/03/2021 09:09 50 19 34 1 23/03/2021 09:09 50 19 34 1''' lst = data .split('\n') lst = [i.split() for i in lst] print(lst) with open("out.csv", "w", newline="") as f: writer = csv.writer(f) writer.writerows(lst)
Output:[['23/03/2021', '09:09', '50', '18', '34', '1'],
['23/03/2021', '09:09', '50', '18', '34', '1'],
['23/03/2021', '09:09', '50', '19', '34', '1'],
['23/03/2021', '09:09', '50', '19', '34', '1']]
# out.csv
23/03/2021,09:09,50,18,34,1
23/03/2021,09:09,50,18,34,1
23/03/2021,09:09,50,19,34,1
23/03/2021,09:09,50,19,34,1