[英]how to calculate dominant frequency use numpy.fft in python
I have this data frame about vehicle vibration and I want to calculate the dominant frequency of the vibration.我有这个关于车辆振动的数据框,我想计算振动的主频率。 I know that we can calculate it using numpy.fft, but I have no idea how can I apply numpy.fft to my data frame.我知道我们可以使用 numpy.fft 计算它,但我不知道如何将 numpy.fft 应用于我的数据帧。 Please enlighten me how to do it in python.请告诉我如何在 python 中做到这一点。 Thankyou.谢谢你。
A dataframe column is a NumPy array effectively dataframe 列有效地是 NumPy 阵列
df = pd.DataFrame({"Vibration":[random.uniform(2,10) for i in range(10)]})
df["fft"] = np.fft.fft(df["Vibration"].values)
print(df.to_string())
output output
Vibration fft
0 8.212039 63.320213+0.000000j
1 5.590523 2.640720-2.231825j
2 8.945281 -2.977825-5.716229j
3 6.833036 4.657765+5.649944j
4 5.150939 -0.216720-0.445046j
5 3.174186 10.592292+0.000000j
6 9.054791 -0.216720+0.445046j
7 5.830278 4.657765-5.649944j
8 5.593203 -2.977825+5.716229j
9 4.935937 2.640720+2.231825j
df = pd.DataFrame({"Vibration":[random.uniform(2,10) for i in range(800)]})
df.assign(
fft=df.groupby(df.index // 15)["Vibration"].transform(lambda s: np.fft.fft(list(s)).astype("object")),
grpfirst=df.groupby(df.index // 15)["Vibration"].transform(lambda s: list(s)[0])
)
Without knowing how the DataFrame looks like, and which fields you need to use for your calculations, you can apply any function to dataframe using .apply()
在不知道 DataFrame 的外观以及需要使用哪些字段进行计算的情况下,您可以使用 .apply 将任何 function 应用于.apply()
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.