Examples
import numpy as np
import pandas as pd
countries_population = {"Italy": 60550000, "France": 65130728,
"Russia": 435000, "Iceland": 435000,
"Palau": 435000, "Brazil": 21104900,
"Nauru": 11600, "Tuvalu": 11600,
"Bermuda": 11600, "Tokelau": 1440}
s = pd.Series(countries_population)
s
The n largest elements where n=5 by default.
s.nlargest()
The n largest elements where n=4. Default keep value is ‘first’ so Russia will be kept.
s.nlargest(4)
The n largest elements where n=4 and keeping the last duplicates. Palau will be kept since
it is the last with value 435000 based on the index order.
s.nlargest(4, keep='last')
The n largest elements where n=5 with all duplicates kept. Note that the returned Series has five elements
due to the three duplicates.
s.nlargest(5, keep='all')