0

I have a pandas dataframe df with overlapping timespans that looks like this:

                   min                 max  grp
0  2013-06-19 18:49:37 2013-06-19 18:49:37    1
0  2013-06-19 18:49:37 2014-07-26 13:56:24    1
1  2013-07-16 03:05:57 2013-07-17 13:11:57    2
2  2013-08-01 03:26:35 2013-08-01 03:26:35    3
1  2013-08-19 06:20:32 2013-08-20 02:32:19    4
3  2013-08-19 07:04:34 2013-08-20 02:01:36    4
2  2013-09-14 09:08:47 2017-06-19 20:11:32    5
4  2013-09-14 22:11:48 2013-09-15 02:14:49    5
5  2013-10-13 21:51:21 2013-10-13 21:51:21    6
6  2013-10-14 03:41:18 2013-10-15 03:17:31    6
3  2013-10-15 03:17:31 2013-10-15 03:17:31    6
7  2013-10-15 04:07:45 2013-10-15 04:07:45    6
8  2013-11-03 07:03:55 2013-11-03 07:03:55    7
9  2013-11-22 02:06:16 2013-11-22 02:06:16    8
10 2013-11-22 02:31:07 2013-11-22 02:31:07    8

My objective is to get the min of the min and the max of the max for each group grp. I have tried:

df.groupby(['grp'])['min'].agg(['min','max']).reset_index()

But this only groups by the min and max of min, whereas I am looking for the min of min and max of max per group.

For example, after aggregation, grp 6 should have a min of 2013-10-13 21:51:21 and a max of 2013-10-15 04:07:45

Is there a simple solution for this in pandas?

0

1 Answer 1

2
df.groupby('grp').agg({'min': min, 'max': max})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.