【发布时间】:2021-04-09 09:52:26
【问题描述】:
我的数据框包含三列 name、content 和 day
df
content day name
0 first_day 01-01-2017 marcus
1 present 10-01-2017 marcus
2 first_day 01-02-2017 marcus
3 first_day 01-03-2017 marcus
4 absent 05-03-2017 marcus
5 present 20-03-2017 marcus
6 first_day 01-04-2017 bruno
7 present 11-04-2017 bruno
8 first_day 01-05-2017 bruno
9 absent 02-05-2017 bruno
10 first_day 01-06-2017 bruno
11 absent 02-06-2017 bruno
12 payment 09-06-2017 bruno
我正在尝试找出用户month wise 的行连续有first_day、absent 和present。
样本输出:
content day name absent_after_present
0 first_day 01-01-2017 marcus False
1 first_day 01-02-2017 marcus False
2 first_day 01-03-2017 marcus True
3 first_day 01-04-2017 bruno False
4 first_day 01-05-2017 bruno False
5 first_day 01-06-2017 bruno True
例如:marcus 有 first_day,absent 和 present 连续来自 01-03-2017,05-03-2017 和
20-03-2017 在same month。所以marcus状态应该是True
【问题讨论】:
-
最后一行的
content字段应该是present而不是payment,对吗?否则,对于 2017 年 6 月的 bruno,没有匹配的模式。
标签: python python-3.x pandas dataframe numpy