There is currently (version 1.1.0) no python datatable.time.week()
or datatable.time.day_of_year()
functions.
Here is some example data:
from datetime import date
import datatable as dt
DT = dt.Frame({"Date": ["2021-05-24", "2021-06-26", "2021-07-27"]}, stype='date32')
datatable.time documentation
One solution, is to convert the datatable
Date
column to a list and process it with appropriate functions from the datetime
library.
Using the given example data:
from datetime import date
import datatable as dt
DT = dt.Frame({"Date": ["2021-05-24", "2021-06-26", "2021-07-27"]}, stype='date32')
weeks_list = [_date.isocalendar().week for _date in DT["Date"].to_list()[0]]
DT[:, "week"] = dt.Frame(weeks_list)
doy_list = [_date.timetuple().tm_yday for _date in DT["Date"].to_list()[0]]
DT[:, "day_of_year"] = dt.Frame(doy_list)
DT
Which should give the following output:
Date week day_of_year
▪▪▪▪ ▪▪▪▪ ▪▪▪▪
0 2021-05-24 21 144
1 2021-06-26 25 177
2 2021-07-27 30 208
3 rows × 3 columns