I want to use pandas rolling function to compare whether the first element is smaller than the second one. I think the following codes should work:
import numpy as np
import pandas as pd
df = pd.DataFrame(data=np.random.randint(0,10,10), columns=['temperature'])
df.rolling(window=2).apply(lambda x: x[0] < x[1])
but it does not work. Instead, I got an error message:
ValueError: 0 is not in range
Does anyone know what caused the issue?
Update:
I know I can use the diff function, but what I really want to do is something like this
df.rolling(window=3).apply(lambda x: x[0] < x[1] < x[2])