Skip to content

Instantly share code, notes, and snippets.

@mzaradzki
Created July 2, 2017 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzaradzki/a2863e32db70efc7dd6bef7a1407bae1 to your computer and use it in GitHub Desktop.
Save mzaradzki/a2863e32db70efc7dd6bef7a1407bae1 to your computer and use it in GitHub Desktop.
# Split date_recorded stamp (string) into year, month, day of month, day of week features
from dateutil import parser
dfX['date_recorded_year'] = dfX['date_recorded'].apply(lambda x: int(x.split('-')[0]))
dates.append('date_recorded_year')
dfX['date_recorded_month'] = dfX['date_recorded'].apply(lambda x: int(x.split('-')[1]))
dates.append('date_recorded_month')
# WARNING : probably not usefull for this dataset
dfX['date_recorded_day'] = dfX['date_recorded'].apply(lambda x: int(x.split('-')[2]))
dates.append('date_recorded_day')
# for weekday convert to string to "categorize"
dfX['date_recorded_weekday'] = dfX['date_recorded'].apply(lambda x: str(parser.parse(x).weekday()))
dates.append('date_recorded_weekday')
# for is_weekend convert to int to "binarize"
dfX['date_recorded_isweekend'] = dfX['date_recorded'].apply(lambda x: int(parser.parse(x).weekday() in [5,6]))
dates.append('date_recorded_isweekend')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment