{
  "name": "Distinct-value counting functions in pandas and NumPy: return type and missing-value handling",
  "description": "Compares five documented functions that count or list distinct values (DataFrame.nunique, Series.nunique, Series.value_counts, Series.unique, numpy.unique): what each returns and how it treats missing values by default. Compiled from the official pandas and NumPy API reference pages.",
  "page": "https://casrai.org/guides/nunique-pandas",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-19T09:05:00Z",
  "temporalCoverage": "2026-11 (pandas 3.1.1 documentation)",
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Function",
      "unit": "",
      "description": ""
    },
    {
      "name": "Returns",
      "unit": "",
      "description": ""
    },
    {
      "name": "Default missing-value handling",
      "unit": "",
      "description": ""
    },
    {
      "name": "Documented parameters controlling it",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Function": "DataFrame.nunique",
      "Returns": "Series with the number of distinct elements per column (axis=0) or per row (axis=1)",
      "Default missing-value handling": "NaN ignored (dropna=True)",
      "Documented parameters controlling it": "axis, dropna"
    },
    {
      "Function": "Series.nunique",
      "Returns": "An integer: the number of unique elements",
      "Default missing-value handling": "NA values excluded by default (dropna=True)",
      "Documented parameters controlling it": "dropna"
    },
    {
      "Function": "Series.value_counts",
      "Returns": "Series of counts of unique values, most frequent first by default",
      "Default missing-value handling": "NaN excluded (dropna=True)",
      "Documented parameters controlling it": "normalize, sort, ascending, bins, dropna"
    },
    {
      "Function": "Series.unique",
      "Returns": "Unique values in order of appearance, as a NumPy array or ExtensionArray; not sorted",
      "Default missing-value handling": "Not stated on the page",
      "Documented parameters controlling it": "none"
    },
    {
      "Function": "numpy.unique",
      "Returns": "Sorted unique elements of an array, optionally with indices, inverse indices and counts",
      "Default missing-value handling": "Multiple NaN values collapse into one when equal_nan is True",
      "Documented parameters controlling it": "return_index, return_inverse, return_counts, axis, equal_nan, sorted"
    }
  ],
  "sources": [
    {
      "title": "pandas documentation: pandas.DataFrame.nunique",
      "url": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.nunique.html",
      "accessed": "2026-11-17"
    },
    {
      "title": "pandas documentation: pandas.Series.nunique",
      "url": "https://pandas.pydata.org/docs/reference/api/pandas.Series.nunique.html",
      "accessed": "2026-11-17"
    },
    {
      "title": "pandas documentation: pandas.Series.value_counts",
      "url": "https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html",
      "accessed": "2026-11-17"
    },
    {
      "title": "pandas documentation: pandas.Series.unique",
      "url": "https://pandas.pydata.org/docs/reference/api/pandas.Series.unique.html",
      "accessed": "2026-11-17"
    },
    {
      "title": "NumPy documentation: numpy.unique",
      "url": "https://numpy.org/doc/stable/reference/generated/numpy.unique.html",
      "accessed": "2026-11-17"
    }
  ]
}