Selecting the smallest of the largest
This recipe can be used to create catchy news headlines such as Out of the Top 100 Universities, These 5 have the Lowest Tuition, or From the Top 50 Cities to Live, these 10 are the Most Affordable.
During analysis, it is possible that you will first need to find a grouping of data that contains the top n values in a single column and, from this subset, find the bottom m values based on a different column.
In this recipe, we find the five lowest budget movies from the top 100 scoring movies by taking advantage of the convenience methods: .nlargest
and .nsmallest
.
How to do it…
- Read in the movie dataset, and select the columns:
movie_title
,imdb_score
, andbudget
:>>> movie = pd.read_csv("data/movie.csv") >>> movie2 = movie[["movie_title", "imdb_score", "budget"]] >>> movie2.head() movie_title imdb_score budget 0 Avatar ...