#NEWLINE# def is_weekend( data ) : #NEWLINE# #INDENT# "\n    Adds a binary is_weekend column to a pandas DataFrame \n    \n    Args:\n        data - a pandas DataFrame containing a 'created_time' column of\n               datetime objects\n    Returns:\n        A DataFrame with an additional 'is_weekend' column\n        if data['created_time'][i] is Friday, Saturday or Sunday then\n        data['is_weekend'][i] = 1\n    " #NEWLINE# data [ 'is_weekend' ] = 0 #NEWLINE# weekend_days = { 4 , 5 , 6 } #NEWLINE# for idx in weekend_days . index : #NEWLINE# #INDENT# wd = data . created_time [ idx ] . weekday ( ) #NEWLINE# if ( wd in weekend_days ) : #NEWLINE# #INDENT# data [ 'is_weekend' ] [ idx ] = 1 #NEWLINE# #UNINDENT# #UNINDENT# return data