You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术问询:计算同一站点同周跨年份的prop均值(缺失周设为NA)

计算同站点同周跨年份的prop均值

原始数据

year week site prop 
2020 3    A    0.2  
2020 3    B    0.1    
2020 4    A    0.3  
2020 4    B    0.5  
2021 3    A    0.9  
2021 3    B    0.7  
2021 4    A    0.1  
2021 4    B    0.8  
2021 5    A    0.1  
2021 5    B    0.8  

需求

  • 对同一站点、同一周的prop值,计算其在不同年份的均值,新增为mean字段
  • 若某站点的某周仅存在于单个年份,则mean字段填NA
  • 示例:站点A第3周2020年prop为0.2、2021年为0.9,均值为0.55

期望输出

year week site prop mean
2020 3    A    0.2  0.55
2020 3    B    0.1  0.4  
2020 4    A    0.3  0.2
2020 4    B    0.5  0.065
2021 3    A    0.9  0.55
2021 3    B    0.7  0.4
2021 4    A    0.1  0.2
2021 4    B    0.8  0.065
2021 5    A    0.1  NA
2021 5    B    0.8  NA

内容的提问来源于stack exchange,提问作者novice_coder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 18:35:30