Estimate power spectral density of time series DF using scipy.welch
<p>I have a pandas DF with datetime index with spacing = 200ms and corresponding values for each index as shown</p>

<pre><code>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]
</code></pre>

<p>I want to compute the power spectral density using scipy.welch function.</p>

<pre><code>f,pxx =welch(filtered.values.flatten(),5)        
</code></pre>

<p>But when I run this line of code the power density array pxx is nan</p>

<pre><code>In [897]: pxx
Out[897]: 

array([ nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,
</code></pre>

<p>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?</p>

<pre><code>f,pxx =welch(filtered.values.flatten(),5)        
</code></pre>

<p>works fine on my side, make sure you have no missing values in your DF and your dtypes are correct (values are floats) first.    </p>

<p>this should work </p>

<pre><code>filtered = filtered.astype(float)
filtered = filtered.dropna()
f,pxx =welch(filtered.values.flatten(),5)        
</code></pre>

python scipy pandas