个人昵称:lxw-pro
个人主页:欢迎关注 我的主页
个人感悟: “失败乃成功之母”,这是不变的道理,在失败中总结,在失败中成长,才能成为IT界的一代宗师。
# -*- coding = utf-8 -*-
# @Time : 2022/8/7 14:30
# @Author : lxw_pro
# @File : NumPy 矩阵库.py
# @Software : PyCharm
NumPy 中包含了一个矩阵库 numpy.matlib,该模块中的函数返回的是一个矩阵,而不是 ndarray 对象。
import numpy as np
lxw = np.arange(16).reshape(4, 4)
print("原数组为:\n", lxw)
print("转置过的数组为:\n", lxw.T)
matlib.empty()
函数返回一个新的矩阵
import numpy.matlib
kk = np.matlib.empty((3, 3)) # 填充为随机数据
print(kk)
numpy.matlib.zeros()
函数创建一个以 0 填充的矩阵
ll = np.matlib.zeros((3, 3))
print(ll)
numpy.matlib.ones()
函数创建一个以 1 填充的矩阵
yy = np.matlib.ones((3, 3))
print(yy)
numpy.matlib.eye() 函数返回一个矩阵,对角线元素为 1,其他位置为零
dd = np.matlib.eye(n=3, M=4, k=0, dtype=float)
print(dd)
numpy.matlib.rand()
函数创建一个给定大小的矩阵,数据是随机填充的
sj = np.matlib.rand((3, 3))
print(sj)
e = np.matrix('1, 2;3, 4')
print(e)
r = np.asarray(e)
print(r)
原数组为:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]
[12 13 14 15]]
转置过的数组为:
[[ 0 4 8 12]
[ 1 5 9 13]
[ 2 6 10 14]
[ 3 7 11 15]]
[[ nan 0.0000000e+000 1.1581509e-311]
[2.0236929e-320 0.0000000e+000 0.0000000e+000]
[0.0000000e+000 0.0000000e+000 0.0000000e+000]]
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]]
[[0.39836727 0.16983388 0.91118039]
[0.77283047 0.24608713 0.72451454]
[0.32447712 0.21523051 0.4374776 ]]
[[1 2]
[3 4]]
[[1 2]
[3 4]]
—————————————————————————————————
# -*- coding = utf-8 -*-
# @Time : 2022/8/7 19:48
# @Author : lxw_pro
# @File : pandas-12 练习.py
# @Software : PyCharm
import pandas as pd
import matplotlib.pyplot as plt
lxw = pd.read_excel("site.xlsx")
print(lxw)
Unnamed: 0 Unnamed: 0.1 create_dt ... yye sku_cost_prc lrl
0 0 1 2016-11-30 ... 8.8 6.77 30.00%
1 1 2 2016-11-30 ... 7.5 5.77 30.00%
2 2 3 2016-11-30 ... 5.0 3.85 30.00%
3 3 4 2016-11-30 ... 19.6 7.54 30.00%
4 4 5 2016-12-02 ... 13.5 10.38 30.00%
.. ... ... ... ... ... ... ...
751 751 752 2016-12-31 ... 1.0 0.77 30.00%
752 752 753 2016-12-31 ... 2.0 1.54 30.00%
753 753 754 2016-12-31 ... 1.0 0.77 30.00%
754 754 755 2016-12-31 ... 7.6 2.92 30.00%
755 755 756 2016-12-31 ... 3.3 2.54 30.00%
[756 rows x 8 columns]
zh = lxw['sku_cost_prc'].rolling(5).sum()
print(zh)
0 NaN
1 NaN
2 NaN
3 NaN
4 34.31
...
751 10.89
752 10.51
753 8.36
754 9.90
755 8.54
Name: sku_cost_prc, Length: 756, dtype: float64
lxw['sku_cost_prc'].plot()
lxw['sku_cost_prc'].rolling(5).mean().plot()
lxw['sku_cost_prc'].rolling(20).mean().plot()
plt.show()
wh = lxw.shift(5)
print(wh)
Unnamed: 0 Unnamed: 0.1 create_dt ... yye sku_cost_prc lrl
0 NaN NaN NaN ... NaN NaN NaN
1 NaN NaN NaN ... NaN NaN NaN
2 NaN NaN NaN ... NaN NaN NaN
3 NaN NaN NaN ... NaN NaN NaN
4 NaN NaN NaN ... NaN NaN NaN
.. ... ... ... ... ... ... ...
751 746.0 747.0 2016-12-31 ... 20.0 2.00 40.00%
752 747.0 748.0 2016-12-31 ... 5.0 1.92 30.00%
753 748.0 749.0 2016-12-31 ... 3.8 2.92 30.00%
754 749.0 750.0 2016-12-31 ... 1.8 1.38 30.00%
755 750.0 751.0 2016-12-31 ... 3.9 3.90 2.56%
[756 rows x 8 columns]
wq = lxw.shift(-5)
print(wq)
Unnamed: 0 Unnamed: 0.1 create_dt ... yye sku_cost_prc lrl
0 5.0 6.0 2016-12-02 ... 3.9 3.00 30.00%
1 6.0 7.0 NaN ... 10.8 8.31 30.00%
2 7.0 8.0 2016-12-02 ... 15.5 11.92 30.00%
3 8.0 9.0 2016-12-02 ... 3.5 2.69 30.00%
4 9.0 10.0 2016-12-02 ... NaN 7.31 30.00%
.. ... ... ... ... ... ... ...
751 NaN NaN NaN ... NaN NaN NaN
752 NaN NaN NaN ... NaN NaN NaN
753 NaN NaN NaN ... NaN NaN NaN
754 NaN NaN NaN ... NaN NaN NaN
755 NaN NaN NaN ... NaN NaN NaN
[756 rows x 8 columns]
yj = lxw['sku_cost_prc'].expanding(min_periods=1).mean()
print(yj)
0 6.770000
1 6.270000
2 5.463333
3 5.982500
4 6.862000
...
751 9.549093
752 9.538429
753 9.526769
754 9.517995
755 9.508740
Name: sku_cost_prc, Length: 756, dtype: float64
沉缅于虚幻的梦想,而忘记现实的生活,这是毫无意义的,千万记住。
人往往需要说很多话,然后才能够归至潜默。
点赞,你的认可是我创作的
动力
!
收藏,你的青睐是我努力的方向
!
评论,你的意见是我进步的财富
!
关注,你的喜欢是我长久的坚持
!
欢迎关注微信公众号【程序人生6】,一起探讨学习哦!!!