Why does pandas.Series.corr return Nan whereas numpy or scipy compute a number?
<p>I try to compute correlation between two pandas series. This is what I get from numpy or scipy :</p>

<pre><code>scipy.stats.pearsonr(xfarines["400"].values, yfarines["PROTREF"].values)


(0.71564870605278108, 2.9185934338775347e-23)


pd.np.corrcoef(xfarines["400"].values, yfarines["PROTREF"].values)


array([[ 1.        ,  0.71564871],
   [ 0.71564871,  1.        ]])
</code></pre>

<p>But this is what pandas gives me :</p>

<pre><code>s = xfarines["400"]
s.corr(yfarines["PROTREF"])


nan
</code></pre>

<p>Looking at this question, 
<a href="http://stackoverflow.com/questions/29042603/pandas-df-corr-returns-nan-despite-data-fed-having-populated-data">pandas df.corr() returns NaN despite data fed having populated data</a>
I check if the dtypes are ok and it seems it is :</p>

<pre><code>s.describe()

count    140.000000
mean       0.304078
std        0.057225
min        0.197300
25%        0.250300
50%        0.318500
75%        0.346850
max        0.408600
Name: 400, dtype: float64


yfarines["PROTREF"].describe()

count    140.000000
mean      12.619143
std        2.547644
min        7.600000
25%       10.975000
50%       12.100000
75%       14.590000
max       18.200000
Name: PROTREF, dtype: float64
</code></pre>

<p>Thus I do not understand where the problem comes from ?</p>

<p>Strange that you mention numpy (v 1.8.0) but use the scipy import which may be different.  This is what numpy does</p>

<pre><code>&gt;&gt;&gt; a
array([[ 3.00000000,  0.17157288],
       [ 3.00000000,  1.58578644],
       [ 3.00000000,  3.00000000],
       [ 3.00000000,  4.41421356],
       [ 3.00000000,  5.82842712]])
&gt;&gt;&gt; np.corrcoef(a[:,0], a[:,1],rowvar=0, bias=0, ddof=None)
array([[ nan,  nan],
       [ nan,  1.00000000]]
</code></pre>

<p>Perhaps people with newer version can confirm what it returns, but at least for a vertical line's points that is what is given.
For a horizontal line's points you get</p>

<pre><code>&gt;&gt;&gt; b = np.array([a[:,1],a[:,0]]).T
&gt;&gt;&gt; b
array([[ 0.17157288,  3.00000000],
       [ 1.58578644,  3.00000000],
       [ 3.00000000,  3.00000000],
       [ 4.41421356,  3.00000000],
       [ 5.82842712,  3.00000000]])
&gt;&gt;&gt; np.corrcoef(b[:,0], b[:,1],rowvar=0, bias=0, ddof=None)
array([[ 1.00000000,  nan],
       [ nan,  nan]])
</code></pre>

python pandas numpy correlation