-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_dates.py
33 lines (24 loc) · 998 Bytes
/
get_dates.py
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
30
31
32
import csv
from datetime import datetime
def get_min_max_dates_from_csv(filename):
with open(filename, 'r') as file:
# Create a CSV reader object
csv_reader = csv.reader(file, delimiter=';')
# Read the header
next(csv_reader)
# Initialize variables to hold min and max dates
min_date = datetime.max
max_date = datetime.min
# Iterate through rows to find min and max dates
for row in csv_reader:
date_str = row[1] # Assuming 'Date' column is always at index 1
date = datetime.strptime(date_str, '%y-%m-%d')
if date < min_date:
min_date = date
if date > max_date:
max_date = date
return min_date.strftime('%y-%m-%d'), max_date.strftime('%y-%m-%d')
filename = 'data/data.csv'
min_date, max_date = get_min_max_dates_from_csv(filename)
print("Lowest (earliest) date:", min_date)
print("Highest (latest) date:", max_date)