0
0
Data Analysis Pythondata~5 mins

nunique() for cardinality in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the nunique() function do in data analysis?

The nunique() function counts the number of unique values in a data column or series. It helps find how many different items exist.

Click to reveal answer
beginner
Why is cardinality important in data analysis?

Cardinality tells us how many unique values a feature has. It helps understand data variety and decide how to handle or encode data.

Click to reveal answer
beginner
How do you use nunique() on a pandas DataFrame column?

Use it like this: df['column_name'].nunique(). It returns the count of unique values in that column.

Click to reveal answer
intermediate
What is the difference between count() and nunique()?

count() counts all non-missing values, while nunique() counts only unique values.

Click to reveal answer
intermediate
Can nunique() handle missing values by default?

Yes, by default nunique() ignores missing values (NaN) when counting unique values.

Click to reveal answer
What does df['age'].nunique() return?
AThe number of unique ages in the 'age' column
BThe total number of rows in the DataFrame
CThe number of missing values in 'age'
DThe sum of all ages
If a column has values [1, 2, 2, 3, NaN], what does nunique() return?
A4
B2
C3
D5
Which method counts all non-missing values, not just unique ones?
Acount()
Bnunique()
Csum()
Dmean()
Why might you check cardinality with nunique() before encoding categorical data?
ATo remove missing data
BTo calculate the average value
CTo sort the data
DTo know how many unique categories exist
Does nunique() include NaN values in its count by default?
AYes, always
BNo, it ignores NaN by default
COnly if specified
DIt depends on the data type
Explain how the nunique() function helps understand data cardinality.
Think about how many different items are in a list or column.
You got /3 concepts.
    Describe a real-life example where checking cardinality with nunique() is useful.
    Consider a survey with different answer choices.
    You got /3 concepts.