题解 | #牛客网用户练习的平均次日留存率#
牛客网用户练习的平均次日留存率
https://www.nowcoder.com/practice/1f9e2b9be96b4b27a2476f8f12c5d29f
import pandas as pd x = pd.read_csv('nowcoder.csv') pd.set_option('display.width', 300) pd.set_option('display.max_rows', None) pd.set_option('display.max_columns', None) df=pd.merge(x,x,on='user_id',suffixes=('_a','_b')) df['date_a']=pd.to_datetime(df['date_a']).dt.date df['date_b']=pd.to_datetime(df['date_b']).dt.date cond=df['date_a']==(df['date_b']+pd.DateOffset(days=1)) print(round(df[cond]['user_id'].count()/x['user_id'].count(),2))