【发布时间】:2018-10-15 04:42:17
【问题描述】:
希望有人可以在这里帮助我 我正在尝试在参差不齐的时间索引上创建一个前向滚动窗口。 Pandas 抱怨单调性——这在我的索引中显然得到了尊重。 正常的后向窗口工作正常。
[编辑] 反向时间索引不通过 is_monotonic。所以我猜它需要一个单调 rising 索引,而不仅仅是单调索引。
请大家有更好的选择 非常感谢!
In [352] tmp[::-1]
Out[352]:
stamp
2018-04-23 06:45:16.920 -0.11
2018-04-23 06:45:16.919 -0.03
2018-04-23 06:45:16.918 -0.01
2018-04-23 06:45:16.917 -0.02
2018-04-23 06:45:16.916 0.03
2018-04-23 06:45:16.914 0.03
2018-04-23 06:45:16.911 0.03
2018-04-23 06:45:16.910 0.06
2018-04-23 06:45:16.909 0.09
2018-04-23 06:45:16.908 0.08
2018-04-23 06:45:16.907 0.18
2018-04-23 06:45:16.906 0.28
2018-04-23 06:45:16.905 0.28
2018-04-23 06:45:16.904 0.02
2018-04-23 06:45:16.903 0.09
2018-04-23 06:45:16.902 0.09
2018-04-23 06:45:16.901 0.09
2018-04-23 06:45:16.900 0.09
2018-04-23 06:45:16.899 -0.24
2018-04-23 06:45:16.898 -0.22
2018-04-23 06:45:16.894 -0.22
2018-04-23 06:45:16.799 -0.21
2018-04-23 06:45:16.798 -0.19
2018-04-23 06:45:16.797 -0.21
2018-04-23 06:45:15.057 -0.13
2018-04-23 06:45:15.056 -0.16
2018-04-23 06:45:13.382 -0.04
2018-04-23 06:45:13.381 -0.02
2018-04-23 06:45:13.380 -0.05
2018-04-23 06:45:13.379 -0.08
Name: d66, dtype: float64
In [353]: tmp[::-1].rolling('20L')
Traceback (most recent call last):
File "<ipython-input-355-74bdfcdfbbd1>", line 1, in <module>
tmp[::-1].rolling('20L')
File "C:\Users\luigi\Anaconda3\lib\site-packages\pandas\core\generic.py", line 7067, in rolling
on=on, axis=axis, closed=closed)
File "C:\Users\luigi\Anaconda3\lib\site-packages\pandas\core\window.py", line 2069, in rolling
return Rolling(obj, **kwds)
File "C:\Users\luigi\Anaconda3\lib\site-packages\pandas\core\window.py", line 86, in __init__
self.validate()
File "C:\Users\luigi\Anaconda3\lib\site-packages\pandas\core\window.py", line 1104, in validate
self._validate_monotonic()
File "C:\Users\luigi\Anaconda3\lib\site-packages\pandas\core\window.py", line 1136, in _validate_monotonic
"monotonic".format(formatted))
ValueError: index must be monotonic
In [356]: tmp.index.is_monotonic
Out[356]: True
In [357]: tmp[::-1].index.is_monotonic
Out[357]: False
In [358]: tmp[::-1].index.is_monotonic_decreasing
Out[358]: True
【问题讨论】:
-
看一下github上的this issue,好像还不支持单调指数递减
标签: python python-3.x pandas time-series