是否可以在csv文件中找到峰值,并将峰值添加到同一csv文件的单独列中?(未绘制)



这是我的一段代码,但我不知道如何将此数组作为新列Height以格式获取到原始csv文件?

高度0<1>
日期 级别
01-01-2021 45
2021年2月1日 43 0
2021年1月3日 47
04-01-2021 46 0

我认为您希望分配一个名为height的列,当level是根据find_peaks()的峰值时,该列的值为1。如果是:

# Declare column full of zeros
bestand['height'] = 0
# Get row number of observations that are peaks
idx = find_peaks(x=bestand['level'], height=37)[0]
# Select rows in `idx` and replace their `height` with 1
bestand.iloc[idx, 2] = 1

返回的是:

date  level  height
0  01-01-2021     45       0
1  02-01-2021     43       0
2  03-01-2021     47       1
3  04-01-2021     46       0

我不确定我是否理解你的问题。

你只想保存结果吗?

bastand['Heigth'] = indices
bastand.to_csv('file.csv') 

最新更新