我试图在一个数据帧中找到数据达到最大值的点,保持一段时间,然后再次下降(见下图)。在
我试图找到索引的值第一次到达最大值的位置以及它第一次离开它的位置。我试过以下几种方法。在
ent = data.loc[data['ESC_Command'] == 1600 and data['ESC_Command'].shift() < 1600]
lve = data.loc[data['ESC_Command'] == 1600 and data['ESC_Command'].shift(-1) < 1600]
但是当我运行这个程序时,我得到了以下错误。在
^{pr2}$如果我使用shift运行'equals to 1600'或'<;1600',我得到预期的布尔值列表,但是添加一个逻辑语句会得到错误。别以为有人能帮我弄明白我遗漏了什么?在
提前谢谢!在
您需要使用位运算符(
&
)组合掩码((data['ESC_Command'] == 1600) & (data['ESC_Command'].shift() < 1600)
)。在and
是逻辑运算符,无法比较序列,因此ValueError
。在此外,还可以使用
data['ESC_Command'].max()
动态查找列中的最大值。在相关问题 更多 >
编程相关推荐