how do i sort a dataframe by reordering rows python?

sort_order = {
    'Documentary':0,
    'Film-Noir':1,
    'Biography':2,
    'History':3,
    'War':4,
    'News':5,
    'Animation':6,
    'Musical':7,
    'Music':8,
    'Drama':9
}

df.sort_values(by=['genre'], key=lambda x: x.map(sort_order))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top