Want to find the number of unique dates corresponds to a set of values. If the values of Col1, Col2, Col3 are same then how many instances are there. I could do with only year or month or day, but want to combine all so that I can find for every unique date(yyyy/mm/dd).
BldgID BldgHt Device Date
108 28 760 2018/9/18
108 28 760 2018/10/5
108 28 760 2018/10/18
108 28 760 2018/10/19
104 36 758 2018/10/2
104 36 758 2018/11/2
104 41 758 2018/9/13
104 41 758 2018/10/3
104 41 758 2018/10/16
104 41 758 2018/10/25
104 41 758 2018/11/3
104 41 758 2018/11/7
104 45 758 2018/10/3
104 45 758 2018/11/3
By changing the dt.month to dt.year or dt.day I can get year, month or day wise, but want the entire date wise.
df_test = df.Date.apply(lambda dt: dt.date()).groupby\
([df.BldgID, df.BldgHt, df.Device, df.Date.apply(lambda dt:\
dt.month)]).nunique()
df_test.head(10)
Here is the month-wise values.
BldgID BldgHt Device Date
108 28.0 760 9 1
10 3
104 36.0 758 10 1
11 1
41.0 758 9 1
758 10 3
758 11 2
45.0 758 10 1
45.0 758 11 1
Name: Date, dtype: int64
Desired output:
BldgID BldgHt Device Total_count
108 28.0 760 4
104 36.0 758 2
41.0 758 6
104 45.0 758 2
Total_count is the sum up the counts for every corresponding set of unique 'BldgID, BldgHt, Device'.
Thanks in advance.