Python 3.x 按列分组并按组查找最小和最大日期
我有以下数据集:Python 3.x 按列分组并按组查找最小和最大日期,python-3.x,pandas,Python 3.x,Pandas,我有以下数据集: Time Title 00:00:00 Title #one 00:12:38 Title #one 00:13:39 Title #one 00:33:14 Title #one 00:33:44 Title #two 00:49:27 Title #two 00:49:57 Title #two 00:59:43 Title #two 00:59:51 Title #three 00:59:59 Ti
Time Title
00:00:00 Title #one
00:12:38 Title #one
00:13:39 Title #one
00:33:14 Title #one
00:33:44 Title #two
00:49:27 Title #two
00:49:57 Title #two
00:59:43 Title #two
00:59:51 Title #three
00:59:59 Title #three
01:28:29 Title #three
01:28:38 Title #four
01:29:08 Title #four
01:29:38 Title #four
01:29:59 Title #four
01:37:08 Title #four
01:37:53 Title #four
01:38:53 Title #four
01:46:20 Title #four
我希望能够按标题分组,并返回每个标题的最小和最大时间
我已经能够通过以下方式获得每个标题的最小和最大时间:
df_max = df.groupby(['Title'])['Start time'].max()
df_min = df.groupby(['Title'])['Start time'].min()
但是我真的不明白
df_max
和df_min
返回的是什么,以及我应该如何合并它们…您应该使用.agg
方法
df.groupby(['Title']).agg({'Start time':[min,max]})
它的输出是什么?