Complete the code to count the frequency of each fruit in the list.
import pandas as pd fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple'] counts = pd.Series(fruits).[1]() print(counts)
The value_counts() method counts the frequency of each unique value in a Series.
Complete the code to get the frequency of each color in the DataFrame column 'color'.
import pandas as pd data = {'color': ['red', 'blue', 'red', 'green', 'blue', 'blue']} df = pd.DataFrame(data) color_counts = df['color'].[1]() print(color_counts)
The value_counts() method on a DataFrame column counts the frequency of each unique value.
Fix the error in the code to correctly count the frequency of each animal in the list.
import pandas as pd animals = ['cat', 'dog', 'cat', 'bird', 'dog', 'dog'] counts = pd.Series(animals).[1]() print(counts)
count_values().count() which does not count frequencies.The correct method is value_counts(). The option count_values is incorrect and causes an error.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['data', 'science', 'ai', 'ml', 'python'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
word instead of len(word) for the value.< instead of > in the condition.The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary of uppercase words and their counts for words with count greater than 1.
words = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple'] counts = pd.Series(words).value_counts() result = [1]: [2] for [3], [2] in counts.items() if [2] > 1} print(result)
item instead of word as the loop variable.The dictionary comprehension uses word.upper() as the key, count as the value, and iterates over word, count pairs from counts.items(). It filters counts greater than 1.