hope someone can help me here
I am trying to create a forward rolling window on a ragged time index.
Pandas complains about monotonicity - which is obviously respected in my index.
The normal backward window works just fine.
[EDIT] The reverse time index does not pass is_monotonic. So I guess it requires a monotonic rising index and not just monotonic index.
Anyone has a better alternative please
thanks a lot!
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:UsersluigiAnaconda3libsite-packagespandascoregeneric.py", line 7067, in rolling
on=on, axis=axis, closed=closed)
File "C:UsersluigiAnaconda3libsite-packagespandascorewindow.py", line 2069, in rolling
return Rolling(obj, **kwds)
File "C:UsersluigiAnaconda3libsite-packagespandascorewindow.py", line 86, in __init__
self.validate()
File "C:UsersluigiAnaconda3libsite-packagespandascorewindow.py", line 1104, in validate
self._validate_monotonic()
File "C:UsersluigiAnaconda3libsite-packagespandascorewindow.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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…