Advertisement
Vitaliy_Novichikhin

11.7.2/5 7. Яндекс.Музыка: сортировка данных

Mar 8th, 2022
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import pandas as pd
  2. df = pd.read_csv('music_log_upd.csv')
  3.  
  4. genre_grouping = df.groupby('user_id')['genre_name']
  5.  
  6. def user_genres(group):
  7.     for col in group:
  8.         if len(col[1]) > 50:
  9.             user = col[0]
  10.             return user
  11.  
  12. search_id = user_genres(genre_grouping)
  13. music_user = df[df['user_id'] == search_id]
  14. music_user = music_user[music_user['total_play_seconds'] != 0]
  15. #Cгруппируем данные таблицы по 'genre_name',
  16. # для этого в скобках gropby напишем первое значение music_user
  17. sum_music_user = df.groupby(df[df['user_id'] == search_id])['genre_name']
  18. #Посчитаем количество 'total_play_seconds' из окончательного music_user и выведем на экран
  19. sum_music_user = music_user.groupby(music_user)['total_play_seconds'].count()
  20. print(sum_music_user)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement