I am reading excel files line by line where I have in one column ISO year_week_start : 2020_53 and in second ISO year_week_end : 2021_01
I am looking how to get distance between these two strings
2021_01 - 2020_53 => 1
2020_40 - 2020_30 => 10
I am reading excel files line by line where I have in one column ISO year_week_start : 2020_53 and in second ISO year_week_end : 2021_01
I am looking how to get distance between these two strings
2021_01 - 2020_53 => 1
2020_40 - 2020_30 => 10
Is this what you are looking for?
from datetime import date
def convert(value):
(year, week) = [int(x) for x in value.split('_')]
result = date.fromisocalendar(year, week, 1)
return result
def distance(date1, date2):
date1 = convert(date1)
date2 = convert(date2)
diff = date1 - date2
weeks = diff.days / 7
return weeks
print(distance('2021_01', '2020_53'))
print(distance('2020_40', '2020_30'))
print(distance('2021_01', '1991_01'))
Output
1.0
10.0
1566.0