forked from shenrunzhang/forex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_date_format.py
More file actions
29 lines (22 loc) · 921 Bytes
/
convert_date_format.py
File metadata and controls
29 lines (22 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import csv
import datetime
# Open the input CSV file
with open("broken_dates_2012.csv", "r") as f_in:
# Create a CSV reader
reader = csv.reader(f_in)
# Open the output CSV file
with open("new_dates_dax.csv", "w", newline="") as f_out:
# Create a CSV writer
writer = csv.writer(f_out)
# Iterate over the rows in the input file
for row in reader:
# Get the date from the first column
date_str = row[0]
# Parse the date string using the mm/dd/yyyy format
date = datetime.datetime.strptime(date_str, "%d/%m/%Y")
# Format the date using the dd/mm/yyyy format
new_date_str = date.strftime("%m/%d/%Y")
# Replace the date in the first column with the new date string
row[0] = new_date_str
# Write the modified row to the output file
writer.writerow(row)