Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫数据帧调整_Python_Pandas_Dataframe - Fatal编程技术网

Python 熊猫数据帧调整

Python 熊猫数据帧调整,python,pandas,dataframe,Python,Pandas,Dataframe,我有一些数据如下: +-----+-------+-------+--------------------+ | Sys | Event | Code | Duration | +-----+-------+-------+--------------------+ | | 1 | 65 | 355.52 | | | 1 | 66 | 18.78 | | | 1 |

我有一些数据如下:

+-----+-------+-------+--------------------+
| Sys | Event | Code  | Duration           |
+-----+-------+-------+--------------------+
|     |     1 |    65 |             355.52 |
|     |     1 |    66 |              18.78 |
|     |     1 |    66 |             223.42 |
|     |     1 |    66 |             392.17 |
|     |     2 |    66 |             449.03 |
|     |     2 |    66 |             506.03 |
|     |     2 |    66 |              73.93 |
|     |     3 |    66 |             123.17 |
|     |     3 |    66 |              97.85 |
+-----+-------+-------+--------------------+
现在,对于每个
code
,我想对所有
Event=1
持续时间进行求和,依此类推,而不考虑
Sys
。我该如何处理这个问题?

正如DYZ所说:

df.groupby(['Code', 'Event']).Duration.sum()
输出:

Code  Event
65    1         355.52
66    1         634.37
      2        1028.99
      3         221.02
Name: Duration, dtype: float64

按事件和代码分组,并使用sum()进行聚合。