0
0
Data Analysis Pythondata~10 mins

Filling missing values (fillna) 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 fill missing values in the DataFrame with zero.

Data Analysis Python
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)
Drag options to blanks, or click blank then click option'
Areplace
Bisnull
Cdropna
Dfillna
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'replace' instead of 'fillna' does not fill NaN values correctly.
Using 'dropna' removes rows instead of filling missing values.
2fill in blank
medium

Complete the code to fill missing values in column 'A' with the mean of that column.

Data Analysis Python
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)
Drag options to blanks, or click blank then click option'
Afillna
Breplace
Cdropna
Dinterpolate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'replace' does not fill NaN values properly.
Using 'interpolate' fills missing values but differently than mean.
3fill in blank
hard

Fix the error in the code to fill missing values in the DataFrame with the string 'missing'.

Data Analysis Python
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)
Drag options to blanks, or click blank then click option'
Afill
Bfill_missing
Cfillna
Dreplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fill' or 'fill_missing' which are not pandas methods.
Using 'replace' which does not fill NaN values correctly.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.

Data Analysis Python
words = ['apple', 'bat', 'car', 'door']
lengths = {word: [1] for word in words if [2]
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using the word in the condition instead of its length.
5fill in blank
hard

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 Analysis Python
data = {'apple': 2, 'banana': 0, 'cherry': 5}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original key without uppercase conversion.
Using incorrect comparison operators like '<' or '==' in the condition.