0

I was looking for some example code and found this project: https://www.fatalerrors.org/a/machine-learning-create-your-own-movie-recommendation-system.html . I do not understand this particular line.

no_user_voted = ratings.groupby('movieId')['rating'].agg('count')

Here movieId and rating are colunms in ratings data frame.

I know what a normal groupby function does but I do not understand this line. Can someone please explain what this line does?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
AxXxelWolf
  • 87
  • 6
  • 2
    What's confusing? the `.agg` ? did you consult the documentation? Stackoverflow should only be used after you've exhausted all other options, which is why you're possibly getting downvoted. – Umar.H Aug 16 '21 at 09:17
  • 1
    It is good to see that others answered your questions but I would like to know what you tried from your self before posting on SO. To be very true this is relatively trivial issue and should have been solved by yourself with little experiments and not posted on SO as a question much less you get answer in forms other than comments. – Abhishek Prajapat Aug 16 '21 at 09:18

2 Answers2

3

It works the same as:

no_user_voted = ratings.groupby('movieId')['rating'].count()

it means for each value of column movieId (groups) count only no missing values of column rating by aggregate function GroupBy.count.

Difference is only count function is passed to GroupBy.agg in your code.

Cimbali
  • 11,012
  • 1
  • 39
  • 68
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • @DeepakTatyajiAhire - ya, your answer is correct, if no missing values. Else it is wrong. – jezrael Aug 16 '21 at 09:19
  • 2
    @DeepakTatyajiAhire Although I am not the one who down voted your answers but I do feel that such questions which don't show proper research and self attempts at understanding should not be appreciated and given answer to in a proper answer form as it will only motivate them to post more such questions and will also hinder their growth. – Abhishek Prajapat Aug 16 '21 at 09:22
  • Anyways, I am happy that @jezrael got the credits and moderators and other folks supported us. – Deepak Tatyaji Ahire Aug 16 '21 at 09:26
  • @DeepakTatyajiAhire - ya, I think not very nice edit answer by another one. – jezrael Aug 16 '21 at 09:28
  • @DeepakTatyajiAhire - Converted to community wiki - so no more credits for me. – jezrael Aug 16 '21 at 09:31
1

The line computes the number of non missing rating for each unique movieId

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
Deepak Tatyaji Ahire
  • 4,883
  • 2
  • 13
  • 35