mua*_*aiz 3 python dataframe pandas
我有一个如下所示的数据框:
Date Attribute1 Attribute2 Attribute3
6/2/2014 7 6 9
6/2/2014 10 9 7
6/2/2014 6 6 8
6/3/2014 6 9 5
6/3/2014 5 7 6
6/4/2014 9 7 5
6/5/2014 8 6 8
6/5/2014 7 10 8
Run Code Online (Sandbox Code Playgroud)
我想在日期上应用每一列值,以便输出如下所示:
Date Attribute1 Attribute2 Attribute3
6/2/2014 23 21 24
6/3/2014 11 16 11
6/4/2014 9 7 5
6/5/2014 15 16 16
Run Code Online (Sandbox Code Playgroud)
我不知道 Pandas 有什么可能的方法来做这个操作。请帮忙。谢谢。
使用 groupby 和 sum 运算符的组合:
df.groupby('Date').sum()
Out[34]:
Attribute1 Attribute2 Attribute3
Date
6/2/2014 23 21 24
6/3/2014 11 16 11
6/4/2014 9 7 5
6/5/2014 15 16 16
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6599 次 |
| 最近记录: |