0
0
Data Analysis Pythondata~10 mins

value_counts() for distributions 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 the frequency of each unique value in the 'color' column.

Data Analysis Python
counts = df['color'].[1]()
Drag options to blanks, or click blank then click option'
Avalue_counts
Bunique
Ccount
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() which counts non-null values but not unique frequencies.
Using unique() which returns unique values but not counts.
2fill in blank
medium

Complete the code to get the relative frequency (proportion) of each unique value in the 'fruit' column.

Data Analysis Python
relative_freq = df['fruit'].value_counts(normalize=[1])
Drag options to blanks, or click blank then click option'
AFalse
B0
CTrue
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving normalize as False returns counts, not proportions.
Passing None or 0 does not activate normalization.
3fill in blank
hard

Fix the error in the code to count values in the 'city' column of DataFrame df.

Data Analysis Python
counts = df.city.[1]()
Drag options to blanks, or click blank then click option'
Avalue_counts
Bcount_values
Cvalues_counts
Dvaluecount
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling the method name causes AttributeError.
Using count_values or similar incorrect names.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 4 letters.

Data Analysis Python
lengths = {word: [1] for word in words if len(word) [2] 4}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > changes the filter condition.
Using word instead of len(word) as dictionary value.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their counts if count is more than 1.

Data Analysis Python
result = [1]: [2] for [3] in counts if counts[[3]] > 1
Drag options to blanks, or click blank then click option'
Aword.upper()
Bcounts[word]
Cword
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of uppercase keys.
Using counts[word] incorrectly or missing the filter condition.