读书报告

1numpy的操作。
import numpy
# 创建数一维数组组
# numpy.array([元素1,元素2,......元素n])
x = numpy.array(['a', '9', '8', '1'])
# 创建二维数组格式
# numpy.array([[元素1,元素2,......元素n],[元素1,元素2,......元素n],[元素1,元素2,......元素n]])
y = numpy.array([[3,5,7],[9,2,6],[5,3,0]])
# 排序
x.sort()
y.sort()
# 取最大值
y1 = y.max()
# 取最小值
y2 = y.main()
# 切片

2.2pandas的操作。

import pandas as pda
# 使用pandas生成数据
# Series代表某一串数据 index指定行索引名称,Series索引默认从零开始
# DataFrame代表行列整合出来的数据框,columns 指定列名
a = pda.Series([8, 9, 2, 1], index=['one', 'two', 'three', 'four'])
# 以列表的格式创建数据框
b = pda.DataFrame([[5,6,2,3],[3,5,1,4],[7,9,3,5]], columns=['one', 'two', 'three', 'four'],index=['one', 'two', 'three'])
# 以字典的格式创建数据框
c = pda.DataFrame({
'one':4, # 会自动补全
'two':[6,2,3],
'three':list(str(982))
})
# b.head(行数)# 默认取前5行头
# b.tail(行数)# 默认取后5行尾
# b.describe() 统计数据的情况 count mean std min 25% max
e = b.head()
f = b.describe()
# 数据的转置,及行变成列,列变成行
g = b.T

2.3 matplotlib的使用

# 折线图/散点图用plot
# 直方图用hist
import matplotlib.pylab as pyl
import numpy as npy
x = [1,2,4,6,8,9]
y = [5,6,7,8,9,0]
pyl.plot(x, y) #plot(x轴数据,y轴数据,展现形式)
# o散点图,默认是直线 c cyan青色 r red红色 m magente品红色 g green绿色 b blue蓝色 y yellow黄色 w white白色
# -直线 --虚线 -. -.形式 :细小虚线
# s方形 h六角形 *星星 + 加号 x x形式 d菱形 p五角星
pyl.plot(x, y, 'D')
pyl.title('name') #名称
pyl.xlabel('xname') #x轴名称
pyl.ylabel('yname') #y轴名称
pyl.xlim(0,20) #设置x轴的范围
pyl.ylim(2,22) #设置y轴的范围
pyl.show()
# 随机数的生成
data = npy.random.random_integers(1,20,100) #(最小值,最大值,个数)
# 生成具有正态分布的随机数
data2 = npy.random.normal(10.0, 1.0, 10000) #(均值,西格玛,个数)
# 直方图hist
pyl.hist(data)
pyl.hist(data2)
# 设置直方图的上限下限
sty = npy.arange(2,20,2) #步长也表示直方图的宽度
pyl.hist(data, sty, histtype='stepfilled') # 去除轮廓
# 子图的绘制和使用
pyl.subplot(2, 2, 2) # (行,列,当前区域)
x1 = [2,3,5,8,6,7]
y1 = [2,3,5,9,6,7]
pyl.plot(x1, y1)
pyl.subplot(2, 2, 1) # (行,列,当前区域)
x1 = [2,3,5,9,6,7]
y1 = [2,3,5,9,6,7]
pyl.plot(x1, y1)
pyl.subplot(2, 1, 2) # (行,列,当前区域)
x1 = [2,3,5,9,6,7]
y1 = [2,3,9,5,6,7]
pyl.plot(x1, y1)
pyl.show()

posted @ 2021-12-12 11:12  罗逸凡  阅读(44)  评论(0)    收藏  举报