Complete the code to calculate the 50th percentile of the data array using 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)
The 50th percentile corresponds to the median value, so we use 50 as the percentile value.
Complete the code to calculate the 0.25 quantile (25th percentile) of the data using scipy's percentile function.
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)
The 25th percentile corresponds to the 0.25 quantile, but scipy expects percentile values between 0 and 100, so use 25.
Fix the error in the code to correctly calculate the 75th percentile using 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)
Percentiles in scipy are given as values between 0 and 100, so 75 is correct for the 75th percentile.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
We want the length of each word (len(word)) and only include words longer than 3 characters (len(word) > 3).
Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] result = { [1]: [2] for word in words if len(word) [3] 4 } print(result)
The dictionary keys are uppercase words (word.upper()), values are lengths (len(word)), and we filter words longer than 4 characters (len(word) > 4).