import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#matplotlib 的字体(font)为黑体(SimHei)
plt.rcParams['font.sans-serif'] = ['SimHei', ]
# matplotlib正确显示正负号
plt.rcParams['axes.unicode_minus'] = False
# 图片高清输出
%config InlineBackend.figure_format = 'svg'
#省略掉plt.show()这一步
%matplotlib inline
初级
本文以xxx表示需要处理的数组
一、符号:
&————并且
|————或者
~————否
any————任一
all————全部
@————数组乘
二、方法(默认axis=0,inplace=False)
1.和
xxx.sum()
np.sum(xxx)
2.算术平均
xxx.mean()
np.mean(xxx)
3.中位数和指定位数
np.median(xxx)
np.quantile(xxx,0.5)
4.最大值
xxx.max()
np.amax()
5.最小值
xxx.min()
np.amin(xxx)
6.极差
xxx.ptp()
np.ptp(xxx)
7.方差
xxx.var()
np.var(xxx)
8.标准差
xxx.std()
np.std(xxx)
9.累计和
(每个值是:自己的值+前面所有值)
xxx.cumsum()
10.最大值的索引
xxx.argmax()
11.最小值的索引
xxx.argmin()
12.获取非0元素
xxx[xxx.nonzero()]
xxxx[xxx !=0]
13.排序(升序)
xxx.sort()
np.sort(xxx)
ascending__升序
xxx.sort_values(ascending=False)
xxx.sort_index()
14.转置
xxx.T
xxx.swapaxes(0,1)
xxx.transpose()