美文网首页我爱编程
numpy处理身高例子

numpy处理身高例子

作者: abc渐行渐远 | 来源:发表于2017-11-15 20:47 被阅读0次

数据如下(姓名, 身高)

order,name,height(cm)
1,George Washington,189
2,John Adams,170
3,Thomas Jefferson,189
4,a,160
5,b,190
6,c,189
7,d,183
8,e,170
9,f,178
10,g,185
11,g1,175
12,g2,150
#coding:utf-8
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

if __name__ == '__main__':
    x = np.arange(10)
    '''
    #numpy基本函数
    print sum(x)
    print np.sum(x)
    print max(x)
    print min(x)
    print np.max(x)
    x = np.array([[1,2,3],[4,5,6]])
    print x
    print x.sum(axis=1) #横向加
    print x.sum(axis=0) #纵向
    '''

    #案列
    data = pd.read_csv('data.csv')
    h = data['height(cm)'] #获取身高
    print h
    print h.max()
    print h.mean()
    print h.std()#标准差
    print np.median(h) #中位数
    #绘图
    plt.title("height")
    plt.xlabel("height(cm)")
    plt.ylabel("number")
    print type(h)
    plt.hist(h)
    plt.show()

相关文章

网友评论

    本文标题:numpy处理身高例子

    本文链接:https://www.haomeiwen.com/subject/acnhvxtx.html