0
0
Pandasdata~10 mins

nunique() for unique counts in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to count unique values in the 'color' column of the DataFrame.

Pandas
unique_colors = df['color'].[1]()
Drag options to blanks, or click blank then click option'
Acount
Bunique
Cnunique
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() which counts all non-null values, not unique ones.
Using unique() which returns unique values but does not count them.
2fill in blank
medium

Complete the code to count unique values in each column of the DataFrame.

Pandas
unique_counts = df.[1]()
Drag options to blanks, or click blank then click option'
Anunique
Bunique
Ccount
Dvalue_counts
Attempts:
3 left
💡 Hint
Common Mistakes
Using unique() which returns arrays of unique values, not counts.
Using value_counts() which works on Series, not DataFrame.
3fill in blank
hard

Fix the error in the code to count unique values in the 'age' column.

Pandas
unique_ages = df['age'].[1]
Drag options to blanks, or click blank then click option'
Anunique()
Bnunique
Cunique()
Dcount()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after nunique.
Using unique() which returns unique values, not count.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their unique letter counts as values.

Pandas
unique_letters = {word: len(set(word)) for word in [1] if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Awords
Bword_list
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name for the list.
Using the wrong comparison operator in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their unique letter counts as values for words longer than 4 letters.

Pandas
result = [1]: [2] for [3] in words if len([3]) > 4
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(set(word))
Cword
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase for keys.
Using the wrong variable name in the loop.