Python机器学习基础 - xiaoxin01/Blog GitHub Wiki
- 逻辑运算
- nparray = np.random.normal(0, 1, (5,5))
- nparray[nparray > 0.5] = 2: 把 array 中大与 0.5 的值修改为 2
- 通用判断
- np.all(nparray > 0.1): 所有的值都大于 0.1 才返回 true
- np.any():任何一个值满足则返回 true
- 三元运算
- np.where(condition, x, y)
- np.logical_and, np.logical_or
- 统计指标
- min:asix 0 代表 列,1 代表 行
- argmix():返回最小值的下标
- argmix(asix = 0),返回每列最大值下标
- max:
- median:
- mean:均值
- std:标准差
- var:方差
- min:asix 0 代表 列,1 代表 行
- np.dot / np.matmul,矩阵相乘
Numpy + matplotlib
stock = pd.DataFrame(nparray)
stoce_code = ["股票{}".format(i+1) for i in range(stock.shape[0])]
pd.date_range:生成连续的时间序列
date = pd.date_range(start="20220807", periods=stock.shape[1]. freq="B")
df = pd.DataFrame(stock, index=stock_code, columns=date)
- head:前 n 行
- tail:后 n 行
- 修改索引:必须全部修改
- reset_index:重设索引
- set_index:可以设置多个索引
- columns.get_indexer:获取下标
pandas 是 先列后行 进行索引查找数据
- loc:先行后列
- iloc:用 index 先行后列
- ix:混合,即将弃用