Datetime Features

In this lesson, we introduce two ways to deal with time features.

DateTime is an essential feature because some behaviors have time patterns. In this lesson, we would introduce two ways to deal with time features.

Notice: In the real world, the time is recorded as the UNIX timestamp. Therefore, all the demos in this lesson will use the UNIX timestamp as the raw DateTime format.

Extract month, week, and hour with pandas.

Users’ behaviors have time patterns. For example, there is a significant difference between what users buy in winter and summer. Users’ preferences vary from time of day to time of day.

Here we show how to extract the month, week, and hour with pandas from UNIX timestamp:

df["col1"] = pd.to_datetime(df['col1'], unit='s')
df["month"] = df["col1"].dt.month

Get hands-on with 1400+ tech skills courses.