0

I have a column in a dataframe called sentiment that has three categories, pos, neg, and neu. I want to call movie_df['sentiment'].sort_values(by=['neg', 'neu', 'pos']) so that they appear in that order in my histogram, but you can't use by= with a Series. It looks like you can only do custom sorting with a dataframe but when I try

frame = movie_df['sentiment'].sort_values(by=['neg', 'neu', 'pos'])

this gives me this error: sort_values() got an unexpected keyword argument 'by'

How can I apply this custom sort?

iamjane
  • 162
  • 8
  • 1
    `movie_df['sentiment'] = pd.Categorical(movie_df['sentiment'], categories=['neg', 'neu', 'pos'],ordered=True)` , then your plot should be in order `['neg', 'neu', 'pos']` , or you can then do `movie_df['sentiment'] .sort_values()` to see it in the data – anky Mar 11 '21 at 15:14
  • 1
    Also, regarding your error please note that `movie_df['sentiment']` is a `Series` object; `Series.sort_values()` does not have a `by` parameter. – Giuseppe Accaputo Mar 11 '21 at 15:17

0 Answers0