I suggest using the rolling
method to find the index of the maximum value computed over the previous 5 rows:
import pandas as pd
import numpy as np
d={'date':np.random.random(10), 'open':np.random.random(10), 'high':np.random.random(10), 'low':np.random.random(10), 'close':np.random.random(10), 'volume':np.random.random(10)}
A1=pd.DataFrame(data=d)
df=A1.rolling(window=5).apply(np.argmax).shift(1).fillna(0)
Then to find the volume associated with this maximum value (in this example for the highest
column):
A1['volume associated with maximum price']=A1.iloc[df.high]['volume']
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…