Title: how to achieve like sumifs function in panda dataframe
Tags: python;dataframe;data-science
Question: I want to add a column to calculate the cumulative uptime.
Below is my dataframe:



What I expect is like below:

```body_id    active_date  uptime cumulative_uptime
51C00195    2017/1/26   1.18   1.18
51C00232    2017/1/12   0.83   0.83
51C00232    2017/1/19   6.28   7.11
51C00232    2017/1/20   9.35   16.46
51C00232    2017/1/21   3.88   20.34
```

Above calculation could be simply achieved in excel using ```sumif```,
however in ```pandas```, I have no idea how to do it.

Could anyone help? Thanks in advance~~

Comment: What is your criteria?

Comment: What does mean uptime 1.18 or cumulative_uptime equal to 0.83. Is it in days? What exactly do you want to do?

Comment: I want the uptime to be added up.

Comment: For cumulative sums there is a `cumsum` function available in pandas. Can you provide your input data as text?


Here is another answer: I think cumsum works for it

```df['cumulative_uptime'] = df.groupby('body_id')['uptime'].cumsum()

&gt;&gt;&gt; import pandas as pd
&gt;&gt;&gt;     
... df = pd.DataFrame({'body_id': ['51C00195','51C00232', '51C00232','51C00232','51C00232'],
...     'active_date': ['2017/1/26','2017/1/12','2017/1/19','2017/1/20','2017/1/21'],
...                    'uptime': [1.18,0.83,6.28,9.35,3.88]
...                        })
&gt;&gt;&gt; 
&gt;&gt;&gt; df['cumulative_uptime'] = df.groupby('body_id')['uptime'].cumsum()
&gt;&gt;&gt; 
&gt;&gt;&gt; df
  active_date   body_id  uptime  cumulative_uptime
0   2017/1/26  51C00195    1.18               1.18
1   2017/1/12  51C00232    0.83               0.83
2   2017/1/19  51C00232    6.28               7.11
3   2017/1/20  51C00232    9.35              16.46
4   2017/1/21  51C00232    3.88              20.34
&gt;&gt;&gt; 
```

Comment for this answer: I think it covers. It has a cumulative value for each row
Comment for this answer: Thank you for the answer. But what I want is to have a cumulative value for each row, instead of only one value for each id.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:07/19/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><dataframe><data-science>', 'Title': 'how to achieve like sumifs function in panda dataframe', 'ViewCount': 84, 'id': 51417135, 'user_AboutMe': None, 'user_AccountId': 13989709.0, 'user_DisplayName': 'ying', 'user_Reputation': 21.0, 'user_Views': 2.0, 'user_id': 10103950.0}}