0

I have a list of events (A, B, C) in a dataframe and two dates for each event and I need to split those dates within their respective months.

Example:

data = {'Name': ['A', 'B', 'C'], 'Start_time': ['2017-12-15', '2017-12-15', '2017-12-15'], 'End_time': ['2018-01-17', '2017-12-22', '2018-05-22']}
df = pd.DataFrame(data)
Events Start_date End_date
A 2017-12-15 2018-01-17
B 2017-12-15 2017-12-22
C 2017-12-15 2018-05-22

Expected results:

Events Start_date End_date
A 2017-12-15 2017-12-31
A 2018-01-01 2018-01-17
B 2017-12-15 2017-12-22
C 2017-12-15 2017-12-31
C 2018-01-01 2018-01-31
C 2018-02-01 2018-02-28
C 2018-03-01 2018-03-31
C 2018-04-01 2018-04-30
C 2018-05-01 2018-05-22
  • Welcome to [Stack Overflow.](https://stackoverflow.com/ "Stack Overflow"). For us to help you, provide a minimal reproducible problem set containing sample input, expected output, actual output, and all relevant code necessary to reproduce the problem. What you have provided falls short of this goal. See [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example "Minimal Reproducible Example") for details. – itprorh66 Sep 17 '22 at 16:23
  • you will have to write own function for this. – furas Sep 17 '22 at 17:20
  • in duplicated answer I found intenresting `pd.date_range('2017-12-15', '2018-01-17', freq="M')` which gives missing `2017-12-31`, and if you add `timedelta(days=1)` then you should get also missing `2018-01-01`. And similar way you can do with longer ranges. – furas Sep 17 '22 at 18:35
  • @furas thanks for sharing, the solution is similar to what I am looking for... – Control Solution Sep 18 '22 at 21:03

0 Answers0