我有这样的df:
Timestamp Time Power Total Energy ID Energy
2020-04-09 06:45:00 2020-04-09 04:44:40.559719 7500 5636690.0 1 140.0
2020-04-09 06:46:00 2020-04-09 04:44:40.559719 7500 5636710.0 1 160.0
2020-04-09 06:47:00 NaT NaN NaN NaN NaN
2020-04-09 06:48:00 2020-04-09 04:44:40.559719 7500 5636960.0 1 410.0
2020-04-09 06:49:00 NaT NaN NaN NaN NaN
2020-04-09 06:50:00 NaT NaN NaN NaN NaN
2020-04-09 06:51:00 NaT NaN NaN NaN NaN
... ... ... ... ... ...
2020-04-30 23:55:00 2020-04-29 16:30:38.559871 7500 18569270.0 5 100.0
2020-04-30 23:54:00 NaT NaN NaN NaN NaN
2020-04-30 23:55:00 2020-04-29 16:30:38.559871 7500 18569370.0 5 180.0
不同的循环(df ['ID'])用不同的ID标记。在一个周期内(ID出现在nan值之前和之后),应该平均两条“环绕”线的功率,ID和Time应该继续,并且在列能量中应输入列能量的最后一个现有值。在循环之外(ID之前的ID =下一个ID),功率和能量应设置为0,ID / Time列应设置为“-”。对于塔的总能量,应该简单地继续该值。
预期结果:
Timestamp Time Power Total Energy ID Energy
2020-04-09 06:45:00 2020-04-09 04:44:40.559719 7500 5636690.0 1 140.0
2020-04-09 06:46:00 2020-04-09 04:44:40.559719 7500 5636710.0 1 160.0
2020-04-09 06:47:00 2020-04-09 04:44:40.559719 7500 5636710.0 1 160.0
2020-04-09 06:48:00 2020-04-09 04:44:40.559719 7500 5636960.0 1 410.0
2020-04-09 06:49:00 - 0 5636960.0 - 0
2020-04-09 06:50:00 - 0 5636960.0 - 0
2020-04-09 06:51:00 - 0 5636960.0 - 0
... ... ... ... ... ...
2020-04-30 23:55:00 2020-04-29 16:30:38.559871 7500 18569270.0 5 100.0
2020-04-30 23:54:00 2020-04-29 16:30:38.559871 7500 18569270.0 5 100.0
2020-04-30 23:55:00 2020-04-29 16:30:38.559871 7500 18569370.0 5 180.0