Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
SciPy - Statistical Functions (scipy.stats) Basics
What is wrong with this code snippet?
from scipy.stats import describe
arr = [1, 2, 3, None, 5]
stats = describe(arr)
print(stats.mean)
AMissing import of numpy
Bdescribe cannot process lists, only numpy arrays
Cstats.mean is not a valid attribute
DThe list contains None, causing a TypeError during calculation
Step-by-Step Solution
Solution:
  1. Step 1: Check data validity

    The list contains a None value, which is not numeric.
  2. Step 2: Understand impact on describe

    describe tries to compute mean and variance but fails due to None causing a TypeError.
  3. Final Answer:

    The list contains None, causing a TypeError during calculation -> Option D
  4. Quick Check:

    Non-numeric values cause calculation errors [OK]
Quick Trick: Remove None or NaN before describe [OK]
Common Mistakes:
MISTAKES
  • Assuming describe handles None automatically
  • Thinking lists are unsupported
  • Confusing attribute names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes