I want to create a new column in a Pandas DataFrame by evaluating multiple conditions in an if-then-else block.
if events.hour <= 6: events[\'time_slice\
You could create a function:
def time_slice(hour): if hour <= 6: return 'night' elif hour <= 12: return 'morning' elif hour <= 18: return 'afternoon' elif hour <= 23: return 'evening'
then events['time_slice'] = events.hour.apply(time_slice) should do the trick.
events['time_slice'] = events.hour.apply(time_slice)