题解 | #牛客网用户练习的平均次日留存率#
牛客网用户练习的平均次日留存率
https://www.nowcoder.com/practice/1f9e2b9be96b4b27a2476f8f12c5d29f
import pandas as pd pd.set_option("display.max_columns", None) # 显示所有的列,而不是以……显示 pd.set_option("display.max_rows", None) # 显示所有的行,而不是以……显示 pd.set_option("display.width", None) # 不自动换行显示 df = pd.read_csv("nowcoder.csv") df['date'] = pd.to_datetime(df.date).dt.date df1 = df.copy() df1['date'] = df1['date'] + pd.Timedelta(days=1) totle = pd.merge(df,df1,how='inner',on=['user_id','date']) n = totle['user_id'].count() n1 = df['user_id'].count() print(round(n / n1,2)) # df = pd.read_csv('nowcoder.csv',sep=',') # df['date'] = pd.to_datetime(df['date']).dt.date # df1 = df.copy() # df1['date'] = df1['date'] + pd.Timedelta(days=1) # total = pd.merge(df,df1,how='inner',on=['user_id','date']) # n = total['user_id'].count() # n1 = df['user_id'].count() # print(round(n / n1 ,2))