Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from matplotlib import pyplot as plt
- sessions = pd.read_csv('users_sessions_data.csv')
- sessions['session_start_ts'] = pd.to_datetime(sessions['session_start_ts'])
- # определяем год и месяц начала сессии
- sessions['session_year'] = sessions['session_start_ts'].dt.year
- sessions['session_month'] = sessions['session_start_ts'].dt.month
- sessions_per_user = sessions.groupby(['session_year', 'session_month']).agg(
- {'client_id':['count', 'nunique']})
- sessions_per_user.columns = ['n_sessions', 'n_users']
- sessions_per_user['sess_per_user'] = (
- sessions_per_user['n_sessions']/ sessions_per_user['n_users'])
- print(sessions_per_user)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement