熊猫中有以下数据帧,我想检查HH值是否大于前一行的高值,如果大于,则更新前一行的HH值,并用非值替换当前的HH
How to check if the value of HH > High of the previous row and update as per above procedure ?
请注意,我不想移动列中的所有数据(因此我认为使用shift不是解决方案),我只想基于前一行的“高”数据更改一个特定的数据段
关于节目:
我正在尝试创建一个程序来查找指定金融市场的极小值和极大值,我正在使用“peakdetect”库https://pypi.org/project/peakdetect/
它只生成一个二维最小值和最大值列表:
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'))
'''
清除数据帧结果:
问题是一些LL(Valley)不准确,有时前一行的低价是正确的LL,因此我必须测量并更改图片中提到的LL行
为了帮助您了解班次(-1)的工作原理,请查看以下解决方案。我看了一下图像,创建了原始数据帧
其输出将为:
注意:我创建了一个新列来显示更改。您可以直接更新
High
。您可以给出“High”,而不是df.loc行上的'NewHigh'
。这应该能奏效相关问题 更多 >
编程相关推荐