How to find "price" of previous 'top'?
df = DataFrame({
'price': [1, 2, 4, 2, 1, 2, 3, 2],
'spikes': [None, None, 'top', None, 'bottom', None, 'top', None]
})
In result I want to find value of previous top/bottom price. Expected result would be:
df = DataFrame({
'price': [1, 2, 4, 2, 1, 2, 3, 2],
'spikes': [None, None, 'top', None, 'bottom', None, 'top', None],
'prev_spikes_prices: [None, None, None, None, None, None, 4, None]
})