I am new to Python and I am messing around with some data that I need to have for a project.
I want to read a CSV and write a cleaner version of it to process later on.
['509,1', '22-10-2018', '05:00', '', '', '11473809', '', '', '', '', '290318']
['509,1', '22-10-2018', '15:00', '', '', '', '', '', '27076', '', '', '', '', '', '', '', '400']
The problem is that the text file sometimes has more spaces in a row and sees it as a new column.
509,1 29-08-2018 12:00 22034905 307257
509,1 29-08-2018 14:00 0 0
509,1 29-08-2018 15:00 0 0
509,1 29-08-2018 16:00 0 433
509,1 29-08-2018 17:00 433 433
How can I skip these columns?
import csv
with open('t:/509.txt', 'r') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=" ")
with open('t:/509out.csv', 'w') as new_file:
csv_writer = csv.writer(new_file, delimiter=";")
for line in csv_reader:
print(line)
# csv_writer.writerow(line)
Thanks in advance