Intro to Python for Data Science Learning 8 - NumPy: Basic Statistics
NumPy: Basic Statistics
from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4-numpy?ex=13
Average versus median
You now know how to use numpy functions to get a better feeling for your data. It basically comes down to importingnumpy and then calling several simple functions on the numpyarrays:
import numpy as np
x = [1, 4, 8, 10, 12]
np.mean(x)
np.median(x)
# np_baseball is available
# Import numpy
import numpy as np
# Create np_height from np_baseball
np_height = np.array(np_baseball)[:,0]
# Print out the mean of np_height
print(np.mean(np_height))
# Print out the median of np_height
print(np.median(np_height))
Explore the baseball data
# np_baseball is available
# Import numpy
import numpy as np
# Print mean height (first column)
avg = np.mean(np_baseball[:,0])
print("Average: " + str(avg))
# Print median height. Replace 'None'
med = np.median(np_baseball[:,0])
print("Median: " + str(med))
# Print out the standard deviation on height. Replace 'None'
stddev = np.std(np_baseball[:,0])
print("Standard Deviation: " + str(stddev))
# Print out correlation between first and second column. Replace 'None'
corr = np.corrcoef(np_baseball[:,0],np_baseball[:,1])
print("Correlation: " + str(corr))
Blend it all together
You've contacted FIFA for some data and they handed you two lists. The lists are the following:
positions = ['GK', 'M', 'A', 'D', ...]
heights = [191, 184, 185, 180, ...]
Each element in the lists corresponds to a player. The first list,positions, contains strings representing each player's position. The possible positions are: 'GK' (goalkeeper), 'M' (midfield),'A' (attack) and 'D' (defense). The second list, heights, contains integers representing the height of the player in cm. The first player in the lists is a goalkeeper and is pretty tall (191 cm).
You're fairly confident that the median height of goalkeepers is higher than that of other players on the soccer field. Some of your friends don't believe you, so you are determined to show them using the data you received from FIFA and your newly acquired Python skills.
# heights and positions are available as lists
# Import numpy
import numpy as np
# Convert positions and heights to numpy arrays: np_positions, np_heights
np_positions = np.array(positions)
np_heights = np.array(heights)
# Heights of the goalkeepers: gk_heights
gk_heights = np_heights[np_positions == "GK"]
# Heights of the other players: other_heights
other_heights = np_heights[np_positions != "GK"]
# Print out the median height of goalkeepers. Replace 'None'
print("Median height of goalkeepers: " + str(np.median(gk_heights)))
# Print out the median height of other players. Replace 'None'
print("Median height of other players: " + str(np.median(other_heights)))
Intro to Python for Data Science Learning 8 - NumPy: Basic Statistics的更多相关文章
- Intro to Python for Data Science Learning 6 - NumPy
NumPy From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4-numpy?ex=1 ...
- Intro to Python for Data Science Learning 7 - 2D NumPy Arrays
2D NumPy Arrays from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4- ...
- Intro to Python for Data Science Learning 5 - Packages
Packages From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functio ...
- Intro to Python for Data Science Learning 2 - List
List from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-2-python-list ...
- Intro to Python for Data Science Learning 4 - Methods
Methods From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-function ...
- Intro to Python for Data Science Learning 3 - functions
Functions from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functi ...
- Intermediate Python for Data Science learning 2 - Histograms
Histograms from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib? ...
- Intermediate Python for Data Science learning 1 - Basic plots with matplotlib
Basic plots with matplotlib from:https://campus.datacamp.com/courses/intermediate-python-for-data-sc ...
- Intermediate Python for Data Science learning 3 - Customization
Customization from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotl ...
随机推荐
- 【咸鱼教程】基于系统时间的计时器DateTimer(不受FPS影响)
教程目录一 计时器简介二 计时器实现三 Demo下载 一 计时器简介在手机上跑游戏时,可能由于运动物体过多,导致帧频太低,计时不准确.比如一些倒计时的游戏,可能倒计时30s,变成了35s.比如ipho ...
- [VS]VS2010如何使用Visual Studio Online在线服务管理团队资源(在线TFS)
前言 Visual Studio Online,也就是以前的Team Foundation Service,从名字可以看出这是一个团队资源管理服务.在微软的云基础架构中运行,无需安装或配置任何服务器, ...
- jdbc(1)(三)DBCP、C3P0、Proxool 、 BoneCP开源连接池的简介
简介 使用评价 项目主页 DBCP DBCP是一个依赖Jakarta commons-pool对象池机制的数据库连接池.DBCP可以直接的在应用程序用使用 可以设置最大和最小连 ...
- React 组件协同关系
组件协同的两种方法,1种是纵向的协同,就是组件嵌套,重点在于代码的封装,2种是横向协同也就是Mixin,组件抽离,重点在于代码复用 1.组件嵌套,父组件通过属性向子组件,子组件可以通过事件处理函数以委 ...
- python---使用pycharm运行py文件
在pycharm中新建一个.py的文件,那么如何使用pycharm来运行这个文件呢? 第一步:选择这个三角(即Edit configuration)进入设置 第二步:设置文件名和路径 第三步:设置完成 ...
- HDU 3642 - Get The Treasury - [加强版扫描线+线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- iOS多线程编程之线程的状态(转载)
一.简单介绍 线程的创建: self.thread=[[NSThread alloc]initWithTarget:self selector:@selector(test) object:nil]; ...
- 学习计划 mysql 主从复制
网上资料繁多,需要跳多少坑才能实现,跳跳就知道了. -- 主从复制 如题:主数据库进行的操作,从数据库进行备份. -- 原理 有关于这方面的原理网上也是一搜一大片,去看看吧.肯定没错. 这里简单说一下 ...
- 洛谷CF264B Good Sequences dp
解题报告:dp+数论 解题报告: 传送门! 开始看这题的时候想挂了,,,想了个显然是错解的想法,,,就是,我也不知道我怎么想的,鬼迷心窍地就想开个数组存每个质因数的倍数的出现次数,然后排下序的max就 ...
- python中执行shell命令行read结果
+++++++++++++++++++++++++++++ python执行shell命令1 os.system 可以返回运行shell命令状态,同时会在终端输出运行结果 例如 ipython中运行如 ...