MCPcopy Create free account
hub / github.com/Chapter-7/Recommended-News / mean_diff_time_func

Function mean_diff_time_func

news2.py:87–91  ·  view source on GitHub ↗
(df, col)

Source from the content-addressed store, hash-verified

85user_click_merge = user_click_merge.sort_values('click_timestamp')
86
87def mean_diff_time_func(df, col):
88 df = pd.DataFrame(df, columns=[col])
89 df['time_shift1'] = df[col].shift(1).fillna(0)
90 df['diff_time'] = abs(df[col] - df['time_shift1'])
91 return df['diff_time'].mean()
92
93mean_diff_click_time = user_click_merge.groupby('user_id').apply(lambda x: mean_diff_time_func(x, 'click_timestamp'))
94plt.plot(sorted(mean_diff_click_time.values, reverse=True))

Callers 1

news2.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected