0
0
Pandasdata~5 mins

nunique() for unique counts in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ANumber of rows in the DataFrame
BCount of unique values per column
CSum of all values in the DataFrame
DMean of each column
How do you include missing values in the unique count using nunique()?
AUse <code>include_na=True</code>
BSet <code>dropna=True</code>
CSet <code>dropna=False</code>
DMissing values are always included
Which pandas object can you call nunique() on?
ABoth Series and DataFrames
BOnly Series
COnly DataFrames
DOnly numpy arrays
What is the default behavior of nunique() regarding missing values?
AIncludes missing values in count
BReplaces missing values with zero
CRaises an error if missing values exist
DExcludes missing values from count
If a column has values [1, 2, 2, 3, NaN], what does nunique() return by default?
A3
B2
C5
D4
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.