Reputation: 199
I have a pandas dataframe bikes
with many columns, one of which is ts
(datetime64). Format is 7/1/2015 00:00:03
. I would like to create a dayflag
column, which should indicate if the record belongs to the day or the night.
For the dayflag, I tried to adapt a solution provided to another date question I had posted.
bikes['dayflag'] = bikes[(bikes.ts.dt.hour > 5) & (bikes.ts.dt.hour <18)]
, but I get a Wrong number of items passed 18, placement implies 1
error.
Thanks in advance.
Upvotes: 0
Views: 1083
Reputation: 332
I think you are trying to add a table to a column. Try to only assign the condition:
bikes['dayflag'] = (bikes.ts.dt.hour > 5) & (bikes.ts.dt.hour <18)
Upvotes: 1