Recall & Review
beginner
What does the pandas method
nunique() do?It counts the number of unique (different) values in a Series or DataFrame column.
Click to reveal answer
beginner
How do you count unique values in each column of a DataFrame using
nunique()?Use
df.nunique(). It returns a Series with the count of unique values for each column.Click to reveal answer
intermediate
What parameter can you use with
nunique() to include or exclude missing values?The parameter
dropna. By default, dropna=True excludes missing values from the count. Set dropna=False to include them.Click to reveal answer
beginner
How to count unique values in a single pandas Series?
Call
nunique() directly on the Series, like series.nunique().Click to reveal answer
beginner
Why is
nunique() useful in data analysis?It helps quickly understand how many different values exist in data columns, which is useful for data cleaning and exploration.
Click to reveal answer
What does
df.nunique() return?✗ Incorrect
df.nunique() returns the count of unique values for each column in the DataFrame.
How do you include missing values in the unique count using
nunique()?✗ Incorrect
Use dropna=False to include missing values in the unique count.
Which pandas object can you call
nunique() on?✗ Incorrect
nunique() works on both pandas Series and DataFrames.
What is the default behavior of
nunique() regarding missing values?✗ Incorrect
By default, nunique() excludes missing values (dropna=True).
If a column has values [1, 2, 2, 3, NaN], what does
nunique() return by default?✗ Incorrect
By default, missing values are excluded, so unique values are 1, 2, and 3 → count is 3.
Explain how to use
nunique() to find unique counts in a DataFrame and how to handle missing values.Think about the default behavior and how to change it.
You got /3 concepts.
Describe a real-life example where counting unique values with
nunique() helps in data analysis.Consider something like counting unique customers or product categories.
You got /3 concepts.