0
0
Data Analysis Pythondata~10 mins

nunique() for cardinality in Data Analysis Python - 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.

Data Analysis Python
unique_colors = df['color'].[1]()
Drag options to blanks, or click blank then click option'
Anunique
Bcount
Csum
Dmean
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() instead of nunique()
Using sum() which adds values instead of counting unique ones
2fill in blank
medium

Complete the code to find the number of unique values in the 'city' column of the DataFrame.

Data Analysis Python
unique_cities = df['city'].[1]()
Drag options to blanks, or click blank then click option'
Acount
Bvalue_counts
Cunique
Dnunique
Attempts:
3 left
💡 Hint
Common Mistakes
Using unique() which returns an array instead of a count
Using value_counts() which returns counts of all values
3fill in blank
hard

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

Data Analysis Python
unique_products = df['product'].[1]
Drag options to blanks, or click blank then click option'
Anunique
Bnunique()
Ccount()
Dunique()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after nunique
Using unique() which returns unique values, not the count
4fill in blank
hard

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

Data Analysis Python
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
B>
C<
Dletters
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'letters' instead of 'words' as iterable
Using '<' instead of '>' 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, only for words longer than 4 letters.

Data Analysis Python
result = [1]: len(set(word)) for word in words if len(word) [2] 4 and word.isalpha() and word.islower() == [3]
Drag options to blanks, or click blank then click option'
Aword.upper()
B>
CFalse
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of word.upper() for keys
Using '<' instead of '>' for length condition
Using True instead of False for word.islower() check