Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- sessions = pd.read_csv('sessions.csv')
- sessions['session_start'] = pd.to_datetime(sessions['session_start'])
- def get_profiles(sessions):
- profiles = (
- sessions.sort_values(by=['user_id', 'session_start'])
- .groupby('user_id')
- .agg(
- {
- 'session_start': 'first',
- 'channel': 'first',
- 'device': 'first',# допишите код
- 'region': 'first'
- #'user_id': 'nunique'# допишите код
- }
- )
- .rename(columns={'session_start': 'first_ts'})
- .reset_index()
- )
- profiles['dt'] = profiles['first_ts'].dt.date
- profiles['month'] = profiles['first_ts'].astype('datetime64[M]')
- return profiles
- profiles = get_profiles(sessions)
- print(
- profiles.groupby('device'),
- profiles.groupby('region') # допишите код
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement