I have a CSV file (calendar), 5 columns that I want to read and parse with the following conditions using a script:
- Deleting headers (done)
- Change the format of the first column from 01/01/2019 to 20190101 in the First column
The first part of the script is done to skip headers. The second part I think a regex is required but I just don't know how to first remove the / and then move the 0101 from before 2019 to after 2019 so that the result is 20190101
If someone could help that would be great!
def parse_calendar(infile, outfile):
with open(outfile, 'w', newline='') as output:
with open(infile, newline='') as input:
reader = csv.reader(input, delimiter=',', quotechar='"')
next(reader, None) # skip the headers
writer = csv.writer(output, delimiter=',', quotechar='"')
for row in reader: # process each row
writer.writerow(row)
I expect the output to be like the following compared to the initial file:
01/01/2019 New Year's Day N C US
20190101 New Year's Day N C US
/: to `` or backspace("%Y-%m-%d %H-%M-%S")to any form you want to.