Bird
Raised Fist0
Data Analysis Pythondata~20 mins

Handling missing values in Series in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Missing Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of dropna() on a Series with missing values
What is the output of this code?
import pandas as pd
s = pd.Series([1, None, 3, None, 5])
result = s.dropna()
print(result)
Data Analysis Python
import pandas as pd
s = pd.Series([1, None, 3, None, 5])
result = s.dropna()
print(result)
A
0    1.0
2    3.0
4    5.0
dtype: float64
B
0    1
1    NaN
2    3
3    NaN
4    5
dtype: object
C
0    1.0
1    NaN
2    3.0
3    NaN
4    5.0
dtype: float64
D
0    1
2    3
4    5
dtype: int64
Attempts:
2 left
💡 Hint
dropna() removes all missing (NaN) values from the Series.
❓ data_output
intermediate
1:30remaining
Count of missing values in a Series
Given this Series, what is the output of s.isna().sum()?
Data Analysis Python
import pandas as pd
s = pd.Series([10, None, 20, None, 30, None])
print(s.isna().sum())
ANone
B0
C6
D3
Attempts:
2 left
💡 Hint
isna() returns True for missing values, sum counts them.
🔧 Debug
advanced
2:00remaining
Identify the error in filling missing values
What error will this code raise?
import pandas as pd
s = pd.Series([1, None, 3, None, 5])
result = s.fillna(method='backward')
print(result)
Data Analysis Python
import pandas as pd
s = pd.Series([1, None, 3, None, 5])
result = s.fillna(method='backward')
print(result)
ATypeError: fillna() got an unexpected keyword argument 'method'
BValueError: Invalid fill method 'backward'
CAttributeError: 'Series' object has no attribute 'fillna'
DNo error, prints the Series with missing values filled backward
Attempts:
2 left
💡 Hint
Check the valid method names for fillna() in pandas.
🚀 Application
advanced
2:30remaining
Replacing missing values with mean
You have this Series with missing values. Which option correctly replaces missing values with the mean of the non-missing values?
import pandas as pd
s = pd.Series([2, None, 4, None, 6])
mean_val = s.mean()
Data Analysis Python
import pandas as pd
s = pd.Series([2, None, 4, None, 6])
mean_val = s.mean()
A
s.fillna(mean_val, inplace=True)
print(s)
B
s.fillna(method='mean')
print(s)
C
s.replace(None, mean_val)
print(s)
D
s.fillna(s.mean())
print(s)
Attempts:
2 left
💡 Hint
fillna() can replace missing values with a scalar value; inplace modifies the original Series.
🧠 Conceptual
expert
1:30remaining
Effect of dropna() on Series index
After applying dropna() on a Series with missing values, what happens to the index of the resulting Series?
AThe index is dropped and replaced by default integer index
BThe index is reset to a continuous range starting at 0
CThe original index values of non-missing entries are preserved
DThe index becomes a MultiIndex with missing value positions
Attempts:
2 left
💡 Hint
Think about whether dropna() changes the index or just removes rows.

Practice

(1/5)
1. What does the isna() method do when applied to a pandas Series?
easy
A. It replaces missing values with zeros.
B. It removes all missing values from the Series.
C. It counts the number of missing values in the Series.
D. It returns a Series of booleans indicating which values are missing (NaN).

Solution

  1. Step 1: Understand the purpose of isna()

    The isna() method checks each element in the Series and returns True if the value is missing (NaN), otherwise False.
  2. Step 2: Compare with other options

    Removing values is done by dropna(), replacing by fillna(), and counting missing values requires sum() on the boolean Series.
  3. Final Answer:

    It returns a Series of booleans indicating which values are missing (NaN). -> Option D
  4. Quick Check:

    isna() = boolean mask [OK]
Hint: Remember: isna() marks missing values as True [OK]
Common Mistakes:
  • Confusing isna() with dropna()
  • Thinking isna() replaces values
  • Assuming isna() counts missing values
2. Which of the following is the correct syntax to remove missing values from a pandas Series named data?
easy
A. data.dropna()
B. data.isna()
C. data.fillna()
D. data.remove_na()

Solution

  1. Step 1: Identify the method to remove missing values

    The method dropna() removes missing values from a Series.
  2. Step 2: Check other options for correctness

    isna() finds missing values, fillna() replaces them, and remove_na() is not a valid pandas method.
  3. Final Answer:

    data.dropna() -> Option A
  4. Quick Check:

    dropna() removes NaNs [OK]
Hint: Use dropna() to delete missing values from Series [OK]
Common Mistakes:
  • Using fillna() instead of dropna() to remove values
  • Calling a non-existent method remove_na()
  • Confusing isna() with dropna()
3. Given the Series import pandas as pd s = pd.Series([1, None, 3, None, 5]) result = s.fillna(0), what is the value of result?
medium
A. [1, 0, 3, 0, 5]
B. [1, None, 3, None, 5]
C. [0, 0, 0, 0, 0]
D. [1, 1, 3, 3, 5]

Solution

  1. Step 1: Understand fillna(0) on the Series

    The fillna(0) replaces all missing values (None/NaN) with 0.
  2. Step 2: Apply fillna(0) to the Series

    Original Series: [1, None, 3, None, 5]. After fillna(0): [1, 0, 3, 0, 5].
  3. Final Answer:

    [1, 0, 3, 0, 5] -> Option A
  4. Quick Check:

    fillna(0) replaces NaN with 0 [OK]
Hint: fillna(value) replaces NaNs with value [OK]
Common Mistakes:
  • Expecting fillna() to remove values
  • Thinking fillna(0) replaces all values with 0
  • Confusing None with zero already present
4. What is wrong with this code snippet to remove missing values from Series s?
clean_s = s.dropna(inplace=True)
print(clean_s)
medium
A. dropna() does not have an inplace parameter.
B. print(clean_s) will print the original Series with NaNs.
C. dropna(inplace=True) returns None, so clean_s is None.
D. dropna(inplace=True) modifies a copy, not the original Series.

Solution

  1. Step 1: Understand dropna(inplace=True) behavior

    When inplace=True is used, dropna() modifies the Series in place and returns None.
  2. Step 2: Analyze assignment and print

    Assigning clean_s = s.dropna(inplace=True) sets clean_s to None. Printing it shows None, not the cleaned Series.
  3. Final Answer:

    dropna(inplace=True) returns None, so clean_s is None. -> Option C
  4. Quick Check:

    inplace=True returns None [OK]
Hint: dropna(inplace=True) returns None, don't assign it [OK]
Common Mistakes:
  • Assigning dropna(inplace=True) to a variable
  • Expecting dropna() to return cleaned Series with inplace=True
  • Confusing inplace behavior with default dropna()
5. You have a Series s = pd.Series([1, None, 2, None, 100]). You want to replace missing values with the mean of the non-missing values. Which code correctly does this?
hard
A. s.replace(None, s.mean())
B. s.fillna(s.mean())
C. s.dropna().mean()
D. s.fillna(s.median())

Solution

  1. Step 1: Calculate mean of non-missing values

    Using s.mean() calculates the average ignoring missing values.
  2. Step 2: Replace missing values with mean

    fillna(s.mean()) replaces NaNs with the calculated mean.
  3. Step 3: Check other options

    fillna(s.median()) replaces with median, not mean. dropna().mean() calculates mean but does not fill. replace(None, s.mean()) does not work properly for NaN.
  4. Final Answer:

    s.fillna(s.mean()) -> Option B
  5. Quick Check:

    fillna(mean) replaces NaNs with average [OK]
Hint: Use fillna(s.mean()) to replace NaNs with average [OK]
Common Mistakes:
  • Using median instead of mean
  • Calculating mean but not filling missing values
  • Using replace() which doesn't handle NaN properly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard