我爱编程

numpy处理身高例子

2017-11-15  本文已影响0人  abc渐行渐远

数据如下(姓名, 身高)

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()

上一篇 下一篇

猜你喜欢

热点阅读