Reputation: 686
i have a dataset like this:
id service datetime
4 connectsInfo 2016-11-05 06:50:23
4 dayFirstFeed 2016-11-05 06:50:57
4 dayFirstFeed 2016-11-05 06:51:43
4 connectsInfo 2016-11-22 06:42:55
4 dayFirstFeed 2016-11-22 06:42:33
4 connectsInfo 2016-11-22 10:52:11
for each date, I want the min and max time rows
an approach that I have tried:
doc_4.loc[doc_4.groupby(df.request_time.dt.date, as_index=False).request_time.idxmin()]
Edit:
I want the result like this:
date min max
2016-11-05 2016-11-05 06:50:23 2016-11-05 06:51:43
2016-11-22 2016-11-22 06:42:33 2016-11-22 10:52:11
Upvotes: 2
Views: 217
Reputation: 863731
You can use:
df = df.groupby(df.datetime.dt.date, as_index=False).datetime.agg(['min','max'])
Upvotes: 2