I have the following DataFrame in Pandas and I want to check if HH value is greater than the previous row's High value and if it is greater, then update previous rows HH value and replace the current HH with Nonvalue.
How to check if the value of HH > High of the previous row and update as per above procedure ?
Please note that I don't want to shift all data in a column (so using shift is not the solution I think) and I just want to change one specific piece of data based on the previous row's "High" data
About Program:
I'm trying to create a program that finds Minima and Maxima of the specified financial market, and I'm using 'peakdetect' library https://pypi.org/project/peakdetect/?
It simply generates a 2D list of Minima and Maxima :
density = 2
# Temp ref to the array of minima and maxima
high_arr = peakdetect(y_axis =
clean_dataframe['High'],x_axis=clean_dataframe.index,lookahead=density)
low_arr = peakdetect(y_axis =
clean_dataframe['Low'],x_axis=clean_dataframe.index,lookahead=density)
# first index is always for maxima
_hh = pd.DataFrame(high_arr[0])
_hh = _hh.rename(columns={0:'Index',1:'HH'})
# second index is always for minima
_ll = pd.DataFrame(low_arr[1])
_ll = _ll.rename(columns={0:'Index',1:'LL'})
# join all minima and maxima to the
full_df=
clean_dataframe.join(_hh.set_index('Index')).join(_ll.set_index('Index'))
'''
clear_dataframe result:
The problem is some LL (Valley) is not accurate and sometimes the previous row's Low price is the correct LL so I have to measure and change the LL row as mentioned in the picture.