@@ -1849,10 +1849,111 @@ def plot(self) -> GroupByPlot:
18491849 result = GroupByPlot (self )
18501850 return result
18511851
1852- @doc (Series .nlargest .__doc__ )
18531852 def nlargest (
18541853 self , n : int = 5 , keep : Literal ["first" , "last" , "all" ] = "first"
18551854 ) -> Series :
1855+ """
1856+ Return the largest `n` elements.
1857+
1858+ Parameters
1859+ ----------
1860+ n : int, default 5
1861+ Return this many descending sorted values.
1862+ keep : {'first', 'last', 'all'}, default 'first'
1863+ When there are duplicate values that cannot all fit in a
1864+ Series of `n` elements:
1865+
1866+ - ``first`` : return the first `n` occurrences in order
1867+ of appearance.
1868+ - ``last`` : return the last `n` occurrences in reverse
1869+ order of appearance.
1870+ - ``all`` : keep all occurrences. This can result in a Series of
1871+ size larger than `n`.
1872+
1873+ Returns
1874+ -------
1875+ Series
1876+ The `n` largest values in the Series, sorted in decreasing order.
1877+
1878+ See Also
1879+ --------
1880+ Series.nsmallest: Get the `n` smallest elements.
1881+ Series.sort_values: Sort Series by values.
1882+ Series.head: Return the first `n` rows.
1883+
1884+ Notes
1885+ -----
1886+ Faster than ``.sort_values(ascending=False).head(n)`` for small `n`
1887+ relative to the size of the ``Series`` object.
1888+
1889+ Examples
1890+ --------
1891+ >>> countries_population = {
1892+ ... "Italy": 59000000,
1893+ ... "France": 65000000,
1894+ ... "Malta": 434000,
1895+ ... "Maldives": 434000,
1896+ ... "Brunei": 434000,
1897+ ... "Iceland": 337000,
1898+ ... "Nauru": 11300,
1899+ ... "Tuvalu": 11300,
1900+ ... "Anguilla": 11300,
1901+ ... "Montserrat": 5200,
1902+ ... }
1903+ >>> s = pd.Series(countries_population)
1904+ >>> s
1905+ Italy 59000000
1906+ France 65000000
1907+ Malta 434000
1908+ Maldives 434000
1909+ Brunei 434000
1910+ Iceland 337000
1911+ Nauru 11300
1912+ Tuvalu 11300
1913+ Anguilla 11300
1914+ Montserrat 5200
1915+ dtype: int64
1916+
1917+ The `n` largest elements where ``n=5`` by default.
1918+
1919+ >>> s.nlargest()
1920+ France 65000000
1921+ Italy 59000000
1922+ Malta 434000
1923+ Maldives 434000
1924+ Brunei 434000
1925+ dtype: int64
1926+
1927+ The `n` largest elements where ``n=3``. Default `keep` value is 'first'
1928+ so Malta will be kept.
1929+
1930+ >>> s.nlargest(3)
1931+ France 65000000
1932+ Italy 59000000
1933+ Malta 434000
1934+ dtype: int64
1935+
1936+ The `n` largest elements where ``n=3`` and keeping the last duplicates.
1937+ Brunei will be kept since it is the last with value 434000 based on
1938+ the index order.
1939+
1940+ >>> s.nlargest(3, keep="last")
1941+ France 65000000
1942+ Italy 59000000
1943+ Brunei 434000
1944+ dtype: int64
1945+
1946+ The `n` largest elements where ``n=3`` with all duplicates kept. Note
1947+ that the returned Series has five elements due to the three duplicates.
1948+
1949+ >>> s.nlargest(3, keep="all")
1950+ France 65000000
1951+ Italy 59000000
1952+ Malta 434000
1953+ Maldives 434000
1954+ Brunei 434000
1955+ dtype: int64
1956+ """
18561957 f = partial (Series .nlargest , n = n , keep = keep )
18571958 data = self ._obj_with_exclusions
18581959 # Don't change behavior if result index happens to be the same, i.e.
0 commit comments