我有一个带有datetime索引的pandas 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]
我想用scipy.welch函数计算功率谱密度。
f,pxx =welch(filtered.values.flatten(),5)
但是当我运行这行代码时,功率密度数组pxx是nan
In [897]: pxx
Out[897]:
array([ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
在时间序列数据帧上运行welch估计的正确方法是什么?在哪里可以找到导致welch函数输出nan的信息?
答案 0 :(得分:0)
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.
this should work
filtered = filtered.astype(float)
filtered = filtered.dropna()
f,pxx =welch(filtered.values.flatten(),5)