Session Ready
Exercise

Create day-of-week features

We can engineer datetime features to add even more information for our non-linear models. Most financial data has datetimes, which have lots of information in them -- year, month, day, and sometimes hour, minute, and second. But we can also get the day of the week, and things like the quarter of the year, or the elapsed time since some event (e.g. earnings reports).

We are only going to get the day of the week here, since our dataset doesn't go back very far in time. The dayofweek property from the pandas datetime index will help us get the day of the week. Then we will dummy dayofweek with pandas' get_dummies(). This creates columns for each day of the week with binary values (0 or 1). We drop the first column because it can be inferred from the others.

Instructions
100 XP
  • Use the dayofweek property from the lng_df index to get the days of the week.
  • Use the get_dummies function on the days of the week variable, giving it a prefix of 'weekday'.
  • Set the index of the days_of_week variable to be the same as the lng_df index so we can merge the two.
  • Concatenate the lng_df and days_of_week DataFrames into one DataFrame.