Complete the code to fill missing values in the DataFrame with zero.
import pandas as pd data = {'A': [1, 2, None, 4], 'B': [None, 2, 3, 4]} df = pd.DataFrame(data) df_filled = df.[1](0) print(df_filled)
The fillna method replaces missing values with the specified value, here zero.
Complete the code to fill missing values in column 'A' with the mean of that column.
import pandas as pd data = {'A': [1, 2, None, 4], 'B': [5, None, 7, 8]} df = pd.DataFrame(data) mean_value = df['A'].mean() df['A'] = df['A'].[1](mean_value) print(df)
The fillna method fills missing values with the mean calculated.
Fix the error in the code to fill missing values in the DataFrame with the string 'missing'.
import pandas as pd data = {'A': [1, None, 3], 'B': [None, 'x', 'y']} df = pd.DataFrame(data) df_filled = df.[1]('missing') print(df_filled)
The correct method to fill missing values is fillna. Other options are invalid or do not exist.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.
words = ['apple', 'bat', 'car', 'door'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts only if the count is greater than zero.
data = {'apple': 2, 'banana': 0, 'cherry': 5}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
print(result)The dictionary comprehension maps the uppercase key k.upper() to its value v only if the value is greater than zero (> 0).