Binning Pandas Column Of Timestamps
I am trying to bin a column of timestamps in a dataframe. The timestamps are of the format 0:00:00, and I think they are strings. I tried using uber.dtypes() but it keeps returning
Solution 1:
You can try of taking minutes and bin to it
uber = pd.DataFrame()
labels = [str(i)+':01-'+str(i+1)+':00'for i inrange(59)]
uber['Time'] = {0: '0:11:00', 1: '0:17:00', 2: '0:21:00', 3: '0:28:00', 4: '0:33:00'}.values()
uber.Time = pd.to_timedelta(uber.Time)
pd.cut(uber.Time.dt.seconds/60,bins,labels=labels)
Out:
010:01-11:00116:01-17:00220:01-21:00327:01-28:00432:01-33:00Name: Time, dtype: categoryCategories (59, object): [0:01-1:00 < 1:01-2:00 < 2:01-3:00 < 3:01-4:00 ... 55:01-56:00 < 56:01-57:00 < 57:01-58:00 < 58:01-59:00]
Post a Comment for "Binning Pandas Column Of Timestamps"