I currently created a function to apply to a pandas dataframe, as below:
def timebin (col):
timebin = []
for x in range(len(col)):
if x>=0 & x<5:
return 'night'
elif x>5 & x<9:
return 'early_morning'
elif x>8 & x<12:
return 'morning'
elif x>11 & x<15:
return 'afternoon'
elif x>14 & x<18:
return 'late_afternoon'
elif x>17 & x<21:
return 'evening'
else:
return 'night'
timebin.append(x)
return timebin
And applying to a dataframe:
df['new_col'] = timebin(df['col'])
When I try this all I get returned is 'night'. Any suggestions?
Thanks