我有一个包含三列
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
我正在尝试按月查找拥有“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
从2017年3月1日
开始一直有first_day
,absent
和present
,分别对应于2017年3月1日
、2017年3月5日
和2017年3月20日
。因此,marcus
的状态应该是True
。
content
字段应该是present
而不是payment
,对吧?否则,在2017年6月的Bruno中,就没有匹配的模式了。 - SeaBean