+ 7

Python for Data Science - House Prices

You are given an array that represents house prices. Calculate and output the percentage of houses that are within one standard deviation from the mean. To calculate the percentage, divide the number of houses that satisfy the condition by the total number of houses, and multiply the result by 100. I stuck at this question, can anyone help out? This is my code : https://code.sololearn.com/cA255a72a21A

22nd Mar 2021, 1:18 PM
Lai Kai Yong
Lai Kai Yong - avatar
40 Réponses
- 2
you rather need to output percentage of data than count: print(100*count/data.size)
22nd Mar 2021, 1:41 PM
visph
visph - avatar
+ 35
My code import numpy as np data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) m = np.mean(data) s = np.std(data) low = m-s high = m+s print( len(data[(low < data) & (data < high)]) / len(data) *100 )
26th Apr 2021, 8:14 AM
KUMAR SHANU
KUMAR SHANU - avatar
+ 8
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) low = mean-std high = mean+std count = 0 for i in data: if low < i < high: count += 1 result = (count / len(data))*100 print(result)
18th Apr 2021, 6:59 AM
Budhabhushan Waghmare
Budhabhushan Waghmare - avatar
+ 4
Hi! here's my answer m = np.mean(data) d = np.std(data) y1 = m-d y2 = m+d s = len(data [(data > y1) & (data < y2)]) r = (s/len(data))*100 print(r) I hope it helped!
22nd Mar 2021, 7:34 PM
Bruno
Bruno - avatar
+ 4
import numpy as np data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) one line answer✌️ print(len([i for i in data if i > (np.mean(data) - np.std(data)) and i < (np.mean(data) + np.std(data))]) / len(data) * 100)
19th Apr 2021, 9:41 AM
Yurii Ostapenko
Yurii Ostapenko - avatar
+ 3
A short and simple answer for the problem: mean = np.mean(data) std = np.std(data) x=(data[(data <= mean+std) & (data >= mean-std)]) print(x.size/data.size*100)
21st Apr 2021, 8:25 PM
Niklas Hoffmann
+ 2
Lai Kai Yong: Please help me with the first Python for Data Science Basketball Players exercise.
24th Mar 2021, 5:42 AM
kensy Nicolle Gutierrez Flores
kensy Nicolle Gutierrez Flores - avatar
+ 2
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) result = data[np.logical_and(data <= mean + std, data >= mean - std)] print(result.size/data.size*100)
25th Apr 2021, 5:10 AM
Luis Antonio Correa Leyva
Luis Antonio Correa Leyva - avatar
+ 2
print(len([i for i in data if (np.mean(data)-np.std(data))< i < (np.mean(data)+np.std(data))])/len(data)*100)
2nd Dec 2021, 4:25 PM
Roman Malkevich
Roman Malkevich - avatar
+ 2
import numpy as np data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) strd=np.std(data) means=np.mean(data) alt=means-strd ust=means+strd a=(data>alt)&(data<ust) print((len(data[a])/len(data))*100)
5th Feb 2022, 4:38 PM
Erman Konyar
Erman Konyar - avatar
+ 1
import numpy as np data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) low = np.mean(data)-np.std(data) high = np.mean(data)+np.std(data) print (len(data[(data>low)&(data<high)])/len(data)*100)
7th Nov 2022, 3:24 AM
Muhammad Siddiq B
Muhammad Siddiq B - avatar
0
you must compute the mean of your data, then compute the standard deviation and finally count how many data are in the range mean-deviation, mean+deviation...
22nd Mar 2021, 1:21 PM
visph
visph - avatar
0
@visph, I'm still confuse. I had modified my codes but it shows an output but still wrong.
22nd Mar 2021, 1:29 PM
Lai Kai Yong
Lai Kai Yong - avatar
0
Lai Kai Yong check again my previous edited post: np.std should get data as argument ^^
22nd Mar 2021, 1:37 PM
visph
visph - avatar
0
@visph, it does not work...
22nd Mar 2021, 1:40 PM
Lai Kai Yong
Lai Kai Yong - avatar
0
Bruno it havent helped
29th Mar 2021, 5:40 PM
Joshua chola
Joshua chola - avatar
0
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) low = mean-std high = mean+std count = 0 for i in data: if low < i < high: count += 1 result = (count / len(data))*100 print(result)
20th Apr 2021, 2:15 PM
Sarah Koziol
Sarah Koziol - avatar
0
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) a=mean+std b=mean-std c=(data[(data <= a) & (data >= b)]) print(c.size/data.size*100)
3rd Jun 2021, 12:45 PM
Kavuri Karthikeyan
0
COVID Data Analysis You are working with the COVID dataset for California, which includes the number of cases and deaths for each day of 2020. Find the day when the deaths/cases ratio was largest. To do this, you need to first calculate the deaths/cases ratio and add it as a column to the DataFrame with the name 'ratio', then find the row that corresponds to the largest value.
27th Jul 2021, 10:14 PM
Nicole Ortiz Peñaranda
0
25th Aug 2021, 9:08 AM
Abdel-hakh Mahamat Senoussi
Abdel-hakh Mahamat Senoussi - avatar