我有一個帶有兩列的df:
index start_date end_date
0 2000-01-03 2000-01-20
1 2000-01-04 2000-01-31
2 2000-01-05 2000-02-02
3 2000-01-05 2000-02-17
...
5100 2020-12-29 2021-01-11
5111 2020-12-30 2021-03-15
我想在開始日期和結(jié)束日期之間添加所有月結(jié)束日期的列,這樣如果end_date在一個月中間,我仍然會考慮到本月底。所以,我的df看起來像這樣:
index start_date end_date first_monthend second_monthend third_monthend fourth_monthend
0 2000-01-03 2000-01-20 2000-01-31 0 0 0
1 2000-01-04 2000-01-31 2000-01-31 0 0 0
2 2000-01-05 2000-02-02 2000-01-31 2000-02-28 0 0
3 2000-01-05 2000-02-17 2000-01-31 2000-02-28 0 0
... ... ... ... ... ...
5100 2020-12-29 2021-02-11 2020-12-31 2021-01-31 2021-02-28 0
5111 2020-12-30 2021-03-15 2020-12-31 2021-01-31 2021-02-28 2021-03-31
I would be very grateful if you could help me
如果需要解析開始和結(jié)束日期時間之間的月份,并添加每個月的最后一天,請使用帶有
period_range
的自定義lambda函數(shù):如果不使用
0
替換缺少的值: