我有这个时间序列:
Current
2018-09-01 00:00 -0.01
2018-09-01 00:01 -0.03
2018-09-01 00:02 -0.01
2018-09-01 00:03 0.03
2018-09-01 00:04 -0.02
2018-09-01 00:05 -0.04
2018-09-01 00:06 0.05
我试图找到一个Current
值的第一个实例>;0.01。如果我使用
findValue = (df['Current'] > 0.01).idxmax()
我将返回:
2018-09-01 00:03 0.03
。你知道吗
但是,我想忽略前5行,所以返回应该是
2018-09-01 00:06 0.05
我已尝试使用shift():
findValue = (df['Current'] > 0.01).shift(5).idxmax()
但这似乎不对。。。你知道吗
您可以通过索引将^{} 用于seelct all列,而不使用第一个
5
:另一个想法是通过
np.arange
和数据帧的长度创建另一个布尔掩码,并通过&
链接:如果需要在
DatetimeIndex
中按值选择:但是:
idxmax
返回第一个False
值,如果不匹配任何值:可能的解决方案是将
next
与iter
一起使用:如果性能很重要,请检查这个nice@jpp Q/A-Efficiently return the index of the first value satisfying condition in array。你知道吗
相关问题 更多 >
编程相关推荐