![](/img/trans.png)
[英]Python Pandas: Calculate cumulative sum using rolling lookback window
[英]How to calculate cumulative sum in python using pandas of all the columns except the first one that contain names?
以下是 csv 格式的數據:
Name 2012 2013 2014 2015 2016 2017 2018 2019 2020
Jack 1 15 25 3 5 11 5 8 3
Jill 5 10 32 5 5 14 6 8 7
我不希望包含名稱列,因為它會給出錯誤。
我試過了
df.cumsum()
嘗試使用set_index
和reset_index
來保留名稱列:
df.set_index('Name').cumsum().reset_index()
Output:
Name 2012 2013 2014 2015 2016 2017 2018 2019 2020
0 Jack 1 15 25 3 5 11 5 8 3
1 Jill 6 25 57 8 10 25 11 16 10
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.