Created
July 2, 2017 11:52
-
-
Save mzaradzki/a2863e32db70efc7dd6bef7a1407bae1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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