gpt4 book ai didi

python - 与阈值超出相关的 Pandas 指数值

转载 作者:太空宇宙 更新时间:2023-11-04 01:23:03 26 4
gpt4 key购买 nike

我有兴趣报告多个时间序列列中超过阈值的日期。该索引是与时间序列数据相关的站点位置相关的日期时间值和列名称。我需要一个类似于“idxmax”的函数,但要返回时间序列中首次超过阈值的索引。这似乎是一项简单的任务,但我是一名 Python 新用户,需要一些指导。谢谢。

最佳答案

似乎 idxmax 符合要求:

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)

关于python - 与阈值超出相关的 Pandas 指数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19964747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com