pythondatetimepy-datatable

datatable assign month from date column


I'm trying to assign a month number from the date column (with a subset based on on another column):

base = datetime.datetime.today()
date_list = [base - datetime.timedelta(days=x) for x in range(10)]

DT1 = dt.Frame(A = date_list, B = range(10))

I tried

DT1[f.B > 2, update(month = f.A.month)]

AttributeError: 'datatable.FExpr' object has no attribute 'month'

And

DT1[f.B > 2, update(month = f.A.to_list()[0].month)]

AttributeError: 'datatable.FExpr' object has no attribute 'to_list'

How can I call .month on that A column?


Solution

  • Using datatable function time.month(date):

    DT1[dt.f.B > 2, dt.update(month = dt.time.month(dt.f.A))]