I am currently working on the nyc taxi limousine dataset. I would like to create 10 minute time bins for each day.
df['pickup_datetime'] = pd.to_datetime(df['pickup_datetime'])
df['dropoff_datetime'] = pd.to_datetime(df['dropoff_datetime'])
df['week_day'] = df['pickup_datetime'].dt.weekday
df['bin'] = (df['pickup_datetime'].sub(df['pickup_datetime'].min())
.dt.floor('10Min')
.rank(method='dense')
.astype(int))
The above creates bins for the range of pickup datetime. I would like to have each day with 144 time bins specific for that day. I could use the pickup timestamp it into the specific time bin of the day. How is this possible? If can please explain with code to get proper understanding. Thanks in advance!
dt_index = pd.date_range('1/1/2021', '2/1/2021', freq='T')
Generates a date range on a minute-by-minute basis for the time period beginning with 1/1/2021 and ending with 2/1/2021. See pandas.date_range for a full explanation of this function.
for a 10 min interval use:
dt = pd.date_range('1/1/2021 00:00:00', '2/1/2021 23:59:59',freq= "10min")