資源簡介
1.某菜店元月份逐日銷售額(元)資料如下:
257 276 297 252 228 310 240 228265 278 271 292 261 281 301 274
267 280 291 258 272 284 268 303
273 282 263 322 249 269 290
要求:
(1)計算該菜店元月份每日平均銷售收入和標準差以及銷售收入的中位數;
(2)試以10元為組距對該資料進行分組,分為10組,并畫出直方圖;
(3)利用分組數據近似計算該數據的均值、中位數和眾數;
(4)若去掉兩個最高收入額、去掉兩個最低收入額,用切尾均值公式計算其均值;
(5)以10元為組距分為11組,將該數據用莖葉圖表示出來;
(6)計算上述資料的兩個四分位數。
代碼片段和文件信息
print(‘1.1答案:‘)
import?numpy?as?np
import?matplotlib.pyplot?as?plt
arr=[257276297252228310240228265278271292261281301274267280291258272284268303273282263322249269290]
arr_mean=np.mean(arr)#求平均值
arr_std=np.std(arrddof=1)#求標準差
L?=?sorted(arr)#求中位數
print(‘平均值=‘arr_mean)
print(“標準差=“arr_std)
print(“中位數=“L[len(L)//2]?if?len(L)%2==1?else?“%.1f“%(0.5*(L[len(L)//2-1]+L[len(L)//2])))
print(‘1.2答案:‘)
plt.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
plt.rcParams[‘axes.unicode_minus‘]?=?False
import?numpy?as?np
Lenths?=[257276297252228310240228265278271292261281301274267280291258272284268303273282263322249269290]
plt.hist(arr10)
plt.xlabel(‘銷售額‘)
plt.ylabel(‘次數‘)
plt.title(‘直方圖‘)
plt.show()
print(‘1.3答案:‘)
import?numpy?as?np
import?matplotlib.pyplot?as?plt
arr1=[225225235245245255255255255255265265265265265265265275275
- 上一篇:python求解標準差
- 下一篇:抽獎背后的秘密(python抽獎邏輯)
評論
共有 條評論