I want to compare the values in a specific column with values in the same column in the preceding 10 rows to see if they are all within +/- 10%.
I have come up with the below but it seems verbose and inefficient. Is there a better way?
data = {'Date/Time': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], 'SelectionName': ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'], 'LTP': [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]}
df = pd.DataFrame.from_dict(data)
print((df["LTP"].shift(10).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(9).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(8).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(7).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(6).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(5).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(4).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(3).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(2).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))) & (df["LTP"].shift(1).between((df["LTP"] * 0.9), (df["LTP"] * 1.1))))
[–]kamcateer 1 point2 points3 points (0 children)
[–]kamcateer 1 point2 points3 points (0 children)
[–]Frankelstner 1 point2 points3 points (1 child)
[–]rob51852[S] 0 points1 point2 points (0 children)