I have a df like this:
df = pd.DataFrame([[1, 184], [1, 3], [4, 6], [2,183], [7,9], [0,7]], columns=['A', 'B'])
df
A B
0 1 184
1 1 3
2 4 6
3 2 183
4 7 9
5 0 7
I need to iterate through column 'B' and for every cell with a value between 182 and 186, I need to store the value from two cells below that into a variable 'marker'.
I tried:
for val in df['B']:
if 182 < int(val) < 186:
print(val)
marker = df['B'].shift(-2).values[0]
print(marker)
And I get:
184
6.0
183
6.0
But I need:
184
6.0
183
7.0
I would love to hear suggestions for fixing this.