Suppose I have the following dataframe:
df = pd.DataFrame({'c': ['abc', 'def', 'wyx', 'abc', 'wyx'], 'begin_date': ['2020-01-01', '2000-12-23', '2003-07-07', '2005-03-02', '2004-01-01'], 'end_date': ['2020-01-31', '2001-02-02', '2004-03-02', '2005-04-01', '2004-07-04']})
df
c begin_date end_date
abc 2020-01-01 2020-01-31
def 2000-12-23 2001-02-02
wyx 2003-07-07 2004-03-02
abc 2005-03-02 2005-04-01
wyx 2004-01-01 2004-07-04
And I want to group by c and count the number of unique days that are between begin_date and end_date for a row of that c, my final dataframe would be:
end = pd.DataFrame({'c': ['abc', 'def', 'wyx'], 'count': [30, 41, 363]})
end
c count
abc 30
def 41
wyx 363