There's more...

It is possible to sort one column in ascending order while simultaneously sorting another column in descending order. To accomplish this, pass in a list of booleans to the ascending parameter that corresponds to how you would like each column sorted. The following sorts title_year and content_rating in descending order and budget in ascending order. It then finds the lowest budget film for each year and content rating group:

>>> movie4 = movie[['movie_title', 'title_year',
'content_rating', 'budget']]
>>> movie4_sorted = movie4.sort_values(['title_year',
'content_rating', 'budget'],
ascending=[False, False, True])
>>> movie4_sorted.drop_duplicates(subset=['title_year',
'content_rating']).head(10)

By default, drop_duplicates keeps the very first appearance, but this behavior may be modified by passing the keep parameter last to select the last row of each group or False to drop all duplicates entirely.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.124.21