{
  "name": "pandas nlargest keep options on the official documentation example",
  "description": "Compares what DataFrame.nlargest returns on the pandas documentation's nine-country example for each keep option and for a two-column call. Compiled from the DataFrame.nlargest documentation page, which lists the example outputs.",
  "page": "https://casrai.org/guides/pandas-nlargest",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-26T10:30:00Z",
  "temporalCoverage": null,
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Call",
      "unit": "",
      "description": ""
    },
    {
      "name": "Rows returned",
      "unit": "rows",
      "description": ""
    },
    {
      "name": "Row labels returned (in order)",
      "unit": "",
      "description": ""
    },
    {
      "name": "Documented rule",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Call": "nlargest(3, 'population')",
      "Rows returned": 3,
      "Row labels returned (in order)": "France, Italy, Malta",
      "Documented rule": "keep='first' (default) prioritises the first occurrence(s) among ties"
    },
    {
      "Call": "nlargest(3, 'population', keep='last')",
      "Rows returned": 3,
      "Row labels returned (in order)": "France, Italy, Brunei",
      "Documented rule": "keep='last' prioritises the last occurrence(s) among ties"
    },
    {
      "Call": "nlargest(3, 'population', keep='all')",
      "Rows returned": 5,
      "Row labels returned (in order)": "France, Italy, Malta, Maldives, Brunei",
      "Documented rule": "keep='all' keeps all ties of the smallest item, even if more than n rows result"
    },
    {
      "Call": "nlargest(3, ['population', 'GDP'])",
      "Rows returned": 3,
      "Row labels returned (in order)": "France, Italy, Brunei",
      "Documented rule": "Later columns in the list break ties in the earlier column"
    }
  ],
  "sources": [
    {
      "title": "pandas documentation: pandas.DataFrame.nlargest",
      "url": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.nlargest.html",
      "accessed": "2026-11-18"
    }
  ]
}