I have a column of Pandas Datetime64 type elements
df['time']
0 2019-10-04 12:03:53+00:00
1 2019-10-04 11:21:23+00:00
2 2019-10-04 12:23:11+00:00
3 2019-10-04 18:04:52+00:00
4 2019-10-04 12:22:21+00:00
...
2889974 2019-10-11 10:53:19+00:00
2889975 2019-10-11 10:58:38+00:00
2889976 2019-10-10 10:36:47+00:00
2889977 2019-10-10 10:36:47+00:00
2889978 2019-07-08 04:36:45+00:00
Name: time, Length: 2889979, dtype: datetime64[ns, UTC]
AND a column of the corresponding timestamps called df['time_full']
like so;
df['time_full']
0 12:03:53
1 11:21:23
2 12:23:11
3 18:04:52
4 12:22:21
...
2889974 10:53:19
2889975 10:58:38
2889976 10:36:47
2889977 10:36:47
2889978 04:36:45
Name: time_full, Length: 2889979, dtype: object
I want to create slots of 30 minutes throughout the day (basically 48 slots) and assign a slot to all of the values in the df['time']
column. Basically, create a bunch of categorical variables a time stamp. Something like this (just an example):
df['time'] df['slot']
0 2019-10-04 12:03:53+00:00 4
1 2019-10-04 11:21:23+00:00 2
2 2019-10-04 12:23:11+00:00 32
3 2019-10-04 18:04:52+00:00 40
4 2019-10-04 12:22:21+00:00 5
I tried binning the slots using Pandas' pd.cut() method like here, and ended up doing this :
pd.cut(df['time'].astype(np.int64)//10**9,
bins=pd.date_range("00:00", "23:59", freq="30min"))
BUT got an output that looked like :
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
...
2889974 NaN
2889975 NaN
2889976 NaN
2889977 NaN
2889978 NaN
Name: time, Length: 2889979, dtype: category
Categories (47, interval[int64]): [(1575331200000000000, 1575333000000000000] < (1575333000000000000, 1575334800000000000] < (1575334800000000000, 1575336600000000000] < (1575336600000000000, 1575338400000000000] ... (1575408600000000000, 1575410400000000000] < (1575410400000000000, 1575412200000000000] < (1575412200000000000, 1575414000000000000] < (1575414000000000000, 1575415800000000000]]
I also tried using df['time_full']
as bins, but it threw an error since it is a list of strings. I think the issue is that df['time'] is not meant for binning when it has both date and time, but I'm not really sure. Any help would be appreciated.