我需要一个 python 脚本,它可以在 csv 文件中找到每个周期的峰值,格式如下:
时间 | gFx | gFy | gFz |
---|---|---|---|
0 | 0,0039 | 0,0005 | 0,0008 |
... | ... | ... | ... |
8 | 0,0052 | 0,0015 | -0,0002 |
三个点代表的值是大约不同的力。在 8 秒的时间内从 0,0050 到 -0,0050。
我需要首先将 gFy 列中的数字从 0,0050 更改为 0.0050,但它不起作用。请帮帮我。
我试图获取 gFy 列并将
','
替换为 '.'
但我得到一个关键错误:
KeyError: 'gFy'
这意味着 gFy 列不存在,但是当我尝试打印所有列名时,它似乎是正确的列。
这是我的代码:
import pandas as pd
import numpy as np
# read CSV file and split column names by semicolon
df = pd.read_csv('G-forceData.csv', sep='\t')
print(df.columns.values) # used this to see the correct key value of the gFy column
# Convert gFy column to a numpy array of float
gFy = np.array(df['gFy'].str.replace(',', '.').astype(float))
# Print the array
print(gFy)
peaks, _ = np.histogram(gFy, bins=50)
peak_indices = np.where(np.diff(np.sign(np.diff(peaks))) == -2)[0] + 1