- Hands-On Data Science and Python Machine Learning
- Frank Kane
- 128字
- 2021-07-15 17:15:09
Calculating median using the NumPy package
Alright, so computing the median is just as simple as computing the mean. Just like we had NumPy mean, we have a NumPy median function as well.
We can just use the median function on incomes, which is our list of data, and that will give us the median. In this case, that came up to $26,911, which isn't very different from the mean of $26988. Again, the initial data was random, so your values will be slightly different.
np.median(incomes)
The following is the output of the preceding code:
Out[4]: 26911.948365056276
We don't expect to see a lot of outliers because this is a nice normal distribution. Median and mean will be comparable when you don't have a lot of weird outliers.
推薦閱讀
- Extending Jenkins
- Python程序設計教程(第2版)
- 在最好的年紀學Python:小學生趣味編程
- Learning Cython Programming
- Testing with JUnit
- 自己動手寫Java虛擬機
- 算法基礎:打開程序設計之門
- Flash CS6中文版應用教程(第三版)
- 用Python實現深度學習框架
- Python Digital Forensics Cookbook
- Continuous Delivery and DevOps:A Quickstart Guide Second Edition
- Android編程權威指南(第4版)
- Leaflet.js Essentials
- JavaScript全棧開發
- Swift從入門到精通 (移動開發叢書)