Reputation: 1251
I am interested in reporting that date at which a threshold value is exceeded in multiple time series columns. The index is a date time value and column names related to site locations to which the time series data relate. I require a function similar to "idxmax" but to return index at which a threshold is FIRST exceeded in the time series. This seems an easy task but I am a new Python user and need a little guidance. Thanks.
Upvotes: 2
Views: 2125
Reputation: 879561
It seems like idxmax
could fit the bill:
In [44]: x = pd.Series([1,2,3,4,5], index=pd.date_range('2000-1-1', periods=5, freq='M'))
In [45]: x
Out[45]:
2000-01-31 1
2000-02-29 2
2000-03-31 3
2000-04-30 4
2000-05-31 5
Freq: M, dtype: int64
In [46]: x >= 3
Out[46]:
2000-01-31 False
2000-02-29 False
2000-03-31 True
2000-04-30 True
2000-05-31 True
Freq: M, dtype: bool
In [47]: (x >= 3).idxmax()
Out[47]: Timestamp('2000-03-31 00:00:00', tz=None)
Upvotes: 5