0
0
SciPydata~10 mins

Percentiles and quantiles in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the 50th percentile of the data array using scipy.

SciPy
from scipy import stats
import numpy as np
data = np.array([10, 20, 30, 40, 50])
percentile_50 = stats.scoreatpercentile(data, [1])
print(percentile_50)
Drag options to blanks, or click blank then click option'
A25
B50
C75
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using 25 or 75 instead of 50 for the median percentile.
Confusing percentile value with data values.
2fill in blank
medium

Complete the code to calculate the 0.25 quantile (25th percentile) of the data using scipy's percentile function.

SciPy
from scipy import stats
import numpy as np
data = np.array([5, 15, 25, 35, 45])
quantile_25 = stats.scoreatpercentile(data, [1])
print(quantile_25)
Drag options to blanks, or click blank then click option'
A0.25
B0.75
C25
D75
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.25 instead of 25 for the percentile argument.
Mixing up 25th and 75th percentiles.
3fill in blank
hard

Fix the error in the code to correctly calculate the 75th percentile using scipy.

SciPy
from scipy import stats
import numpy as np
data = np.array([2, 4, 6, 8, 10])
percentile_75 = stats.scoreatpercentile(data, [1])
print(percentile_75)
Drag options to blanks, or click blank then click option'
A75
B0.75
C7.5
D0.25
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.75 instead of 75.
Using a data value instead of percentile value.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

SciPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) for the value.
Using < instead of > in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.

SciPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
result = { [1]: [2] for word in words if len(word) [3] 4 }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of word.upper() for keys.
Using < instead of > in the condition.