题解 | #牛客网用户练习的平均次日留存率#
牛客网用户练习的平均次日留存率
https://www.nowcoder.com/practice/1f9e2b9be96b4b27a2476f8f12c5d29f
import pandas as pd df = pd.read_csv('nowcoder.csv',sep = ',') df.date = pd.to_datetime(df.date).dt.date df1 = df.copy() df1.date = df.date + pd.Timedelta(days=1) merge_df = pd.merge(df,df1,how='inner',on=['user_id','date']) num = merge_df.user_id.count() total = df.user_id.count() print(round(num / total,2))