Python机器学习基础 - xiaoxin01/Blog GitHub Wiki

ndarray 计算

  1. 逻辑运算
    1. nparray = np.random.normal(0, 1, (5,5))
    2. nparray[nparray > 0.5] = 2: 把 array 中大与 0.5 的值修改为 2
  2. 通用判断
    1. np.all(nparray > 0.1): 所有的值都大于 0.1 才返回 true
    2. np.any():任何一个值满足则返回 true
  3. 三元运算
    1. np.where(condition, x, y)
    2. np.logical_and, np.logical_or
  4. 统计指标
    1. min:asix 0 代表 列,1 代表 行
      1. argmix():返回最小值的下标
      2. argmix(asix = 0),返回每列最大值下标
    2. max:
    3. median:
    4. mean:均值
    5. std:标准差
    6. var:方差

矩阵计算

  1. np.dot / np.matmul,矩阵相乘

Pandas

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:混合,即将弃用
⚠️ **GitHub.com Fallback** ⚠️