鱼C论坛

 找回密码
 立即注册
查看: 4202|回复: 0

[技术交流] pandas的Series的统计函数

[复制链接]
发表于 2020-12-10 10:55:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
pandas的Series的统计函数
  1. import pandas as pd
  2. import numpy as np
  3. idx =  "hello the cruel world".split()
  4. val =  [1000, 201, 333, 104]
  5. t = pd.Series(val, index = idx)
  6. print (t, "<- t")
  7. print (t.var(), "\t<- var方差")
  8. # var函数计算方差,方差Variance反映的是模型每一次输出结果与模型输出期望(平均值)之间的误差,
  9. # 即模型的稳定性
  10. x =  val
  11. mu = t.mean()
  12. y = [np.square(v - mu) for v in x]
  13. print (np.sum(y) / 3)  # 通过python来验证一下var函数的结果
  14. print (t.std(), "\t<- std标准差")
  15. # mad函数可以计算平均绝对离差(mean absolute deviation),
  16. # 平均绝对离差是用样本数据相对于其平均值的绝对距离来度量数据的离散程度
  17. print (t.mad(), "\t<- mad离差")
  18. van = [1100, 221, 303, 84]
  19. s = pd.Series(van,index=idx)
  20. print(t.cov(s),"\t<- cov协方差")
  21. print (t.corr(y), "\t<- corr相关系数")
  22. print(t.kurt(),, "<- kurt峰度值")
  23. print (x.skew(), "<- skew偏态值")
  24. # Series.cummax : Return cumulative maximum over Series axis.
  25. # Series.cummin : Return cumulative minimum over Series axis.
  26. # Series.cumsum : Return cumulative sum over Series axis.
  27. # Series.cumprod : Return cumulative product over Series axis.即累乘
  28. print (t.cumsum(), "\t<- cumsum")
  29. print (t.cumprod(), "\t<- cumprod")
  30. print (t.cummin(), "\t<- cummin")
  31. print (t.cummax(), "\t<- cummax")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-30 17:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表