Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- df = pd.read_csv('music_log_upd.csv')
- genre_grouping = df.groupby('user_id')['genre_name']
- def user_genres(group):
- for col in group:
- if len(col[1]) > 50:
- user = col[0]
- return user
- search_id = user_genres(genre_grouping)
- music_user = df[df['user_id'] == search_id]
- music_user = music_user[music_user['total_play_seconds'] != 0]
- #Cгруппируем данные таблицы по 'genre_name',
- # для этого в скобках gropby напишем первое значение music_user
- sum_music_user = df.groupby(df[df['user_id'] == search_id])['genre_name']
- #Посчитаем количество 'total_play_seconds' из окончательного music_user и выведем на экран
- sum_music_user = music_user.groupby(music_user)['total_play_seconds'].count()
- print(sum_music_user)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement