条件熊猫的累积总和库

发布于 2025-02-09 08:08:16 字数 653 浏览 0 评论 0原文

数据集

innings matchid over_count  runs_total_inover
1       1000887      1               1.0
1       1000887      2               1.0
1       1000887      50              3.0
2       1000887      1               6.0
2       1000887      50              2.0

我想要这样的

innings matchid over_count  runs_total_inover     sum
1       1000887      1               1.0          1.0  
1       1000887      2               1.0          2.0
1       1000887      50              3.0          5.0 
2       1000887      1               6.0          6.0 
2       1000887      50              2.0          8.0

my data set

innings matchid over_count  runs_total_inover
1       1000887      1               1.0
1       1000887      2               1.0
1       1000887      50              3.0
2       1000887      1               6.0
2       1000887      50              2.0

i want like that

innings matchid over_count  runs_total_inover     sum
1       1000887      1               1.0          1.0  
1       1000887      2               1.0          2.0
1       1000887      50              3.0          5.0 
2       1000887      1               6.0          6.0 
2       1000887      50              2.0          8.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话已封尘 2025-02-16 08:08:16

iiuc,您可以尝试Groupby和Cumsum

df['sum'] = df.groupby('innings')['runs_total_inover'].cumsum()
print(df)

   innings  matchid  over_count  runs_total_inover  sum
0        1  1000887           1                1.0  1.0
1        1  1000887           2                1.0  2.0
2        1  1000887          50                3.0  5.0
3        2  1000887           1                6.0  6.0
4        2  1000887          50                2.0  8.0

IIUC, you can try groupby and cumsum

df['sum'] = df.groupby('innings')['runs_total_inover'].cumsum()
print(df)

   innings  matchid  over_count  runs_total_inover  sum
0        1  1000887           1                1.0  1.0
1        1  1000887           2                1.0  2.0
2        1  1000887          50                3.0  5.0
3        2  1000887           1                6.0  6.0
4        2  1000887          50                2.0  8.0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文