Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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,我有以下数据结构 +------+------+-------+----------------------+--------------------+ | uuid | type | score | next_score_incorrect | next_score_correct | +------+------+-------+----------------------+--------------------+ | 0 | A | 100 | 110

我有以下数据结构

+------+------+-------+----------------------+--------------------+
| uuid | type | score | next_score_incorrect | next_score_correct |
+------+------+-------+----------------------+--------------------+
|    0 | A    |   100 | 110                  | 120                |
|    0 | A    |   110 | 120                  | 120                |
|    0 | B    |   120 | na                   | na                 |
|    1 | B    |    80 | 90                   | 100                 |
|    1 | A    |    90 | 100                  | 100                |
|    1 | B    |   100 | na                   | na                 |
+------+------+-------+----------------------+--------------------+
根据记录,我试图计算同一uuid中的下一个最大分数,但仅从类型B记录(示例列next_score_correct)计算。 到目前为止,我只能通过执行以下操作(列next_score_不正确)来计算下一个最大分数,忽略类型:


我将如何调整我的代码,以考虑到我想要切换到下一个B类型分数,而这不一定是下一个

为什么第4行等于90?不应该,这是一个输入错误@YOLO。
df.sort_values(by='score', ascending=True, inplace=True)
df.groupby('uuid')['score'].shift(periods=-1)