简体   繁体   中英

Ordering pandas dataframe column in ascending order

I have tried to find a specific answer to this question but no luck.

I have created a groupby dataframe where I have found the mean rating of a series of movies. I now have the movie id's as the index, but I want to order all the ratings with the highest rating at the top, lowest at the bottom. I have tried the sort and sort_value function to no avail.

r_cols = ['user_id', 'movie_id', 'rating', 'unix_timestamp']
ratings = pd.read_csv(
    'http://files.grouplens.org/datasets/movielens/ml-100k/u.data', 
    sep='\t', names=r_cols)

grouped_ratings=ratings['rating'].groupby(ratings['movie_id'])
average_rating=grouped_ratings.mean()

按等级降序排序

average_rating.sort_values(ascending=False)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM