I am new to Python, I've looked through the CSV doc and had a look at a few Stack Overflow examples but can't seem to get it right. I have a CSV file that has data that looks like this:
IDCJAC0010,66062,2019,01,01,31.6,1,Y
Index [2:5] are the elements of the date so I'd like to merge those columns and have a '-' between year-month-day so that I can then use the newly created CSV to create a plot with matplotlib. To be clear, the desired output in the new CSV file is:
IDCJAC0010,66062,2019-01-01,31.6,1,Y
My code so far is:
with open(file_in, newline='') as f_in, open(file_out, 'w') as f_out:
reader = csv.reader(f_in, delimiter=',')
new_row = []
for row in reader:
new_row.append(row[0: 2])
amended_row = '-'.join(row[2:5])
new_row.append(amended_row)
new_row.append(row[5:])
The output that I'm getting is:
['IDCJAC0010', '66062'], '2019-01-05', ['37.8', '1', 'Y']