0
Array of house prices, calculate and output the percentage of houses that are within one standard deviation from the mean.
Please help! I've been struggling with this task. The problem is getting the percentage. I already tried summing up the total house prices and the results to get the percentage too, but it didn't work. ........................................................... import numpy as np data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) mean = np.mean(data) std = np.std(data) x = mean - std y = mean + std result = [] for i in result: if i > x and i < y: result.append(i) n = len(result) nd = len(data) answer = (n/nd)*100 print (answer) print ((len(result)/len(data))*100)
3 Respostas
0
Thank you so much.... Can't believe I didn't see the mistake, almost gave me a headache
0
for i in result: --> for i in data:
0
import numpy as np
data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000])
z = np.std(data)
y = np.mean(data)
low = y - z
high = y + z
count = 0
for i in data:
if low < i < high:
count = count + 1
result = (count/ len(data)) * 100
print (result )