小编bos*_*elo的帖子

How to calculate cumulative groupby counts in Pandas with point in time?

I have a df that contains multiple weekly snapshots of JIRA tickets. I want to calculate the YTD counts of tickets.

the df looks like this:

pointInTime   ticketId
2008-01-01         111
2008-01-01         222
2008-01-01         333
2008-01-07         444
2008-01-07         555
2008-01-07         666
2008-01-14         777
2008-01-14         888
2008-01-14         999
Run Code Online (Sandbox Code Playgroud)

So if I df.groupby(['pointInTime'])['ticketId'].count() I can get the count of Ids in every snaphsots. But what I want to achieve is calculate the cumulative sum.

and have a df looks like this:

pointInTime   ticketId …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas pandas-groupby

5
推荐指数
1
解决办法
60
查看次数

标签 统计

dataframe ×1

pandas ×1

pandas-groupby ×1

python ×1