1.将某一列变为日期格式
df_dispatch['Datetime'] = pd.to_datetime(df_dispatch['day'], format="%Y/%m/%d")
2.按日期分组groupby
df_group_dispatch=df_dispatch.groupby('Datetime')
df_group_dispatch.day.describe()
3.获取特定日期2020-10-01分组后的某一列内容(此处以uid为例)
begin = datetime.date(2020,10,1)
df_group_dispatch.get_group(begin).uid
4.留存率计算(此处以从10/01开始到12/31的3日留为例)
begin = datetime.date(2020,10,1)
end = datetime.date(2020,12,31)
d = begin
delta = datetime.timedelta(days=1)
gap = datetime.timedelta(days=3)
while d <= end:
print(df_group_dispatch.get_group(d)[df_group_dispatch.get_group(d)['to_uid'].isin(df_group_dispatch.get_group(d+gap)['to_uid'])].to_uid.count()/df_group_dispatch.get_group(d).to_uid.count())
d+=delta