Python Forum
Finding date count from a list of date range in pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding date count from a list of date range in pandas
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cycle through Numpy range within another range(?) Zero01 0 394 Jul-31-2020, 02:37 PM
Last Post: Zero01
  [pandas] How to reshape the list Mekala 6 552 Jul-26-2020, 12:49 AM
Last Post: Mekala
  How Do I Only Get the Year from Date and Isolate Data for Year? WhatsupSmiley 2 515 Apr-14-2020, 11:45 AM
Last Post: snippsat
  why is the ticker and date different junkone 1 349 Apr-02-2020, 06:34 PM
Last Post: snippsat
  replace nan values by mean group by date.year, date.month wissam1974 5 2,744 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Obtaining Correct Date In Pandas DataFrame eddywinch82 14 1,917 Feb-17-2020, 11:45 AM
Last Post: eddywinch82
  pandas.read_sas with chunksize: IndexError list index out of range axelle 0 531 Jan-28-2020, 09:30 AM
Last Post: axelle
  How to predict with date as input for DecisionTreeRegressor sandeep_ganga 0 408 Dec-12-2019, 03:29 AM
Last Post: sandeep_ganga
  itertuples, datetime, pandas, groupby, in range karlito 0 862 Nov-29-2019, 11:35 AM
Last Post: karlito
  how to list/count the number of dictionaries paul18fr 2 476 Nov-18-2019, 09:50 PM
Last Post: paul18fr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020