It is about a problem I faced while using df.groupby.mea()

I tried calculating the mean as seen from a YT video. It does not calculate mean for my code but does it for the youtuber/mentor.
The code goes:
books = pd.read_csv(‘Books2.csv’, on_bad_lines=‘skip’, low_memory=False)
users = pd.read_csv(‘Users.csv’)
ratings = pd.read_csv(‘Ratings.csv’)



books_rated = books.merge(ratings, on=‘ISBN’).drop(columns=[‘User-ID’, ‘Year-Of-Publication’,‘Image-URL-L’,‘Image-URL-S’])
books_rated.isnull().sum().dropna()



books_rated = books_rated.groupby(‘Book-Title’).count()[‘Book-Rating’].reset_index()
books_rated_avg = books_rated.groupby(‘Book-Title’)[‘Book-Rating’].mean().reset_index()
books_rated_avg.rename(columns={‘Book-Rating’: ‘avg-rating’},inplace=True)

The bold line is where i tried to take the mean of Book-Rating for each group of ‘Book-Title’.
On printing the ‘books_rated_avg’ it is giving me the result same as books_rated. Only the column name got changed.

image

I assume you mean that you are following a Youtube video tutorial.

We cannot possibly diagnose the problem properly, because we cannot see what is in the csv file, so there’s no way we can tell what the expected output should be.

But I can tell you, for example, if there is only one rating per book to begin with, then of course the result for this mean calculation will look the same. For each book, we took a group of ratings which only has one rating in it; obviously the average will just be that same value again.