depreciation warning when I use sklearn imputer
<p>My code is quite simple, but it always pops out the warning like this:</p>

<pre><code>DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will
raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if
your data has a single feature or X.reshape(1, -1) if it contains a single sample.
(DeprecationWarning)
</code></pre>

<p>I don't know why it does not work even if I add <code>s.reshape(-1,1)</code> in the parentheses of <code>fit_transforms</code>.</p>

<p>The code is following:</p>

<pre><code>import pandas as pd

s = pd.Series([1,2,3,np.nan,5,np.nan,7,8])
imp = Imputer(missing_values='NAN', strategy='mean', axis=0)
x = pd.Series(imp.fit_transform(s).tolist()[0])
x
</code></pre>

<p>Besides the warning, your snippet did not interpret by me due to missing <code>import</code>s, and an error (<code>ufunc: isnan not supported</code>) once I got some imports into place. </p>

<p>This code runs without warnings or errors, though:</p>

<pre><code>In [39]: import pandas as pd

In [40]: import numpy as np

In [41]: from sklearn import preprocessing

In [42]: s = pd.Series([1,2,3,np.nan,5,np.nan,7,8])

In [43]: imp = preprocessing.Imputer(strategy='mean', axis=0)

In [44]: x = pd.Series(imp.fit_transform(s.values.reshape(1, -1)).tolist()[0])

In [45]: x
Out[45]: 
0    1.0
1    2.0
2    3.0
3    5.0
4    7.0
5    8.0
dtype: float64
</code></pre>

<p>Note the following:</p>

<ol>
<li><p><code>import</code>s</p></li>
<li><p><code>preprocessing.Imputer(strategy='mean', axis=0)</code> omits your <code>NAN</code> specification (it should be <code>NaN</code>, but as <code>NaN</code> is the default, you can just erase it).</p></li>
<li><p><code>x = pd.Series(imp.fit_transform(s.values.reshape(1, -1)).tolist()[0])</code> reshapes from a 1d array, to a 2d array.</p></li>
</ol>

<p>Your warning was about point 3 - this function wants a 2d matrix, not a 1d vector.</p>

python pandas scikit-learn