简体   繁体   English

使用scipy.welch估算时间序列DF的功率谱密度

[英]Estimate power spectral density of time series DF using scipy.welch

I have a pandas DF with datetime index with spacing = 200ms and corresponding values for each index as shown 我有一个熊猫DF,其日期时间索引的间距为200ms,每个索引的对应值如图所示

print(filtered)

2016-07-14 16:31:19.000 -0.010054
2016-07-14 16:31:19.200 -0.011849
2016-07-14 16:31:19.400 -0.009564
2016-07-14 16:31:19.600 -0.001077

[20038 rows x 1 columns]

I want to compute the power spectral density using scipy.welch function. 我想使用scipy.welch函数计算功率谱密度。

f,pxx =welch(filtered.values.flatten(),5)        

But when I run this line of code the power density array pxx is nan 但是当我运行这行代码时,功率密度数组pxx是nan

In [897]: pxx
Out[897]: 

array([ nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,

What is the proper way to run the welch estimation on a time series dataframe and where might I find information on what causes the welch function to output nan? 在时间序列数据帧上进行韦氏估计的正确方法是什么?在哪里可以找到导致韦氏函数输出nan的信息?

f,pxx =welch(filtered.values.flatten(),5)        

works fine on my side, make sure you have no missing values in your DF and your dtypes are correct (values are floats) first. 在我这边工作正常,请确保您的DF中没有丢失值,并且dtypes正确(值是浮点型)。

this should work 这应该工作

filtered = filtered.astype(float)
filtered = filtered.dropna()
f,pxx =welch(filtered.values.flatten(),5)        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM