It is common practice to convert date to the week number for normalization or feature preprocessing. While this is pretty useful, sometimes we want to compare the week number in a more strict fashion, such that we can order week 50 of last year and week 2 of this year, for example.
Following code shows both
(1) how to get week number of datetime object
(2) get the exacte date of the Monday or Sunday within the same week
get week number for any date
from datetime import timedelta, datetime |
8
get date of Monday or Sunday for any date within the same week
from datetime import timedelta, datetime |
2022-02-21
2022-02-27