【发布时间】:2020-12-03 07:00:39
【问题描述】:
输入:
Column1 Event Time
0 type1 A 2020-11-01 05:26:12
1 type1 A 2020-11-01 05:26:17
2 type1 A 2020-11-01 05:26:22
3 type1 B 2020-11-01 05:26:32
4 type1 B 2020-11-01 05:26:37
5 type1 A 2020-11-01 05:26:42
6 type1 A 2020-11-01 05:26:47
7 type1 C 2020-11-01 05:26:52
8 type1 C 2020-11-01 05:27:02
9 type1 B 2020-11-01 05:27:07
10 type1 B 2020-11-01 05:27:15
期望的输出:
Column1 Event Min(Time) Max(Time) EventEndTime
0 type1 A 2020-11-01 05:26:12 2020-11-01 05:26:22 2020-11-01 05:26:32
1 type1 B 2020-11-01 05:26:32 2020-11-01 05:26:37 2020-11-01 05:26:42
2 type1 A 2020-11-01 05:26:42 2020-11-01 05:26:47 2020-11-01 05:26:52
3 type1 C 2020-11-01 05:26:52 2020-11-01 05:27:02 2020-11-01 05:27:07
4 type1 B 2020-11-01 05:27:07 2020-11-01 05:27:15
我已尝试但无法仅对相邻的相同事件进行分组,我最终通过以下代码行获得了总体最小值和最大值:
data.groupby(['Column1','Event']).agg({'Time': ['min','max']})
【问题讨论】:
标签: python python-3.x pandas pandas-groupby data-analysis