Python Forum
Finding date count from a list of date range in pandas - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Finding date count from a list of date range in pandas (/thread-10530.html)



Finding date count from a list of date range in pandas - trillerducas72 - May-24-2018

I have the pandas df in the following format (with NoOFDays being EndDate - StartDate)

------------------------------------------
|Item | StartDate | EndDate | NoOFDays|
------------------------------------------
| A | 01-Jan-2018| 04-Jan-2018| 4 |
| A | 07-Jan-2018| 08-Jan-2018| 2 |
| B | 03-Jan-2018| 05-Jan-2018| 3 |
| A | 03-Jan-2018| 05-Jan-2018| 3 |
------------------------------------------

And wanted to get the count of each day grouped by item

A 01-Jan-2018 1
A 02-Jan-2018 1
A 03-Jan-2018 2
A 04-Jan-2018 2
A 05-Jan-2018 1
A 06-Jan-2018 0
A 07-Jan-2018 1
A 08-Jan-2018 1
B 01-Jan-2018 0
B 02-Jan-2018 0
B 03-Jan-2018 1
B 04-Jan-2018 1
B 05-Jan-2018 1
B 06-Jan-2018 0
B 07-Jan-2018 0
B 08-Jan-2018 0


The dataset over here isn't straight forward to apply groupby. Meaning , the first row has the following implicit dates - 01 Jan , 02 Jan , 03 Jan , 04 Jan) second row has the dates - 07 Jan , 08-Jan and so on... The output needs to be the occurance of each date in the given date range...I understand I need to use date functionality to get all the dates in each row and then group it. But unsure of how to do this using pandas utilities