My input dataframe is something like this: here for every company we can have multiple salesid and each salesid has unique create date.
CompanyName Salesid Create Date
ABC 1 1-1-2020
ABC 22 4-1-2020
ABC 3 15-1-2020
ABC 4 10-1-2020
XYZ 34 19-2-2020
XYZ 56 23-2-2020
XYZ 23 11-2-2020
XYZ 87 27-2-2020
XYZ 101 5-2-2020
I want to calculate the mean createdate gap for each company: I am expecting an output in this format:
Name Mean_createdate_gap
ABC 4.66
XYZ 5.5
explanation:
ABC => (3+6+5)/3 = 4.66 (cumulative diff between dates)
XYZ => (6+8+4+4)/4 = 5.5
For this first, we may need to sort the data followed by grouping by companyname. I am not sure how I suppose to implement it.