python - 同一周数 Python Pandas 过去 3 年的滚动平均值
问题描述
只要有可用数据(例如 201932),我就会使用 201632、201732 和 201832 的数据的平均值来查找同一周的平均值。示例:2019 年是年份,32 是周数
解决方案
通用示例,未完全测试,您可以根据需要进行更新,请原谅语法/编译错误
# 1 load your data here
myYearlyWeekAvgList = [[Calendar, WkNumber, France, 0, 201538], [....]]
# 2 initialize variables here
totalSum = 0
movingAves = 0 # track total for that yr
myYear = currentYear # input, for e.g. 2018
# 3 start totals & averages here
for i, x in enumerate(myYearlyWeekAvgList, 1):
T = x[i] # get each row
if x == currentYear # for e.g. if yr is 2018, then sum value
totalSum.append(T[3]) # your revenue in 3rd col I guess
moving_ave = totalSum/i # your average for that col
推荐阅读
- android - 将 Android Studio Gradle 升级到 6.1.1 会破坏 Greendao3GradlePlugin
- python - 有没有办法从文本文件中打印第一行,然后循环打印第二行,然后循环打印第三行等等?
- django - 尝试在 Django 中更新 url 但不断收到错误
- python - 如何在 django 中为电子邮件渲染 png
- typescript - 使用 typeorm 更新实体
- python - discord.py 如何接受可选参数
- javascript - 试图传递属性/组合组件,以堆叠按钮的属性
- c# - 回发后重新绑定控件后,更新面板中的事件未触发
- python - 将 Django 项目部署到 Heroku 时如何解决服务器错误(500)?
- javascript - 如何在我的应用程序中使用数据库 sqlite?