What is the difference between nunique() and unique() in pandas?

Quick Overview

Asks how the pandas methods unique() and nunique() differ in what they return and how they treat missing values. Tests practical pandas knowledge for exploring a column, checking cardinality and counting distinct values per group or across columns.

What is the difference between nunique() and unique() in pandas?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the difference between `nunique()` and `unique()`? Both are pandas methods. Assume you are calling them on a `Series`, such as one column of a `DataFrame`. ```hint Missing values Try both on a column that contains NaN and compare the length of one result with the other. ``` ### What a Strong Answer Covers - What each method returns, including the type of the result - How each one treats missing values, and why the two can disagree - Which pandas objects each method is available on - When you would reach for each one in practice ### Follow-up Questions - Why can `len(s.unique())` differ from `s.nunique()`? - How would you count the distinct (user, product) pairs in a DataFrame? - How do you count the distinct products each user bought?

Overview: Asks how the pandas methods unique() and nunique() differ in what they return and how they treat missing values. Tests practical pandas knowledge for exploring a column, checking cardinality and counting distinct values per group or across columns.

General logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What is the difference between nunique() and unique()?

Both are pandas methods. Assume you are calling them on a Series, such as one column of a DataFrame.

What a Strong Answer Covers Guidance

  • What each method returns, including the type of the result
  • How each one treats missing values, and why the two can disagree
  • Which pandas objects each method is available on
  • When you would reach for each one in practice

Follow-up Questions Guidance

  • Why can len(s.unique()) differ from s.nunique() ?
  • How would you count the distinct (user, product) pairs in a DataFrame?
  • How do you count the distinct products each user bought?