title: Using Imputer in a Pipeline doesn't remove NaNs, gives ''Input contains NaN, infinity or a value too large for dtype('float64')''
body: <p>So I'm using a pipeline to perform a Ridge Regression on some data, which also includes an imputer to remove the NaNs.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  from sklearn.model_selection import train_test_split
  from sklearn.model_selection import cross_val_score
  from sklearn.linear_model import Ridge
  from sklearn.preprocessing import Imputer
  from sklearn.pipeline import Pipeline
  
  #making Data ready
  gapdata = pd.read_csv('/Users/naveedanwer/desktop/Python Files/Life Expectancy Data.csv')
  gapdata.columns = gapdata.columns.str.strip()
  gapdata.rename(columns={'Life expectancy':'life'}, 
                   inplace=True)
  gapdata.Status = gapdata.Status.astype('category')
  
  model_data = gapdata.drop('Country',axis =1)
  model_data = pd.get_dummies(model_data)
  
  #initialize imputer
  imp = Imputer(missing_values = 'NaN', strategy = 'mean', axis = 0)
  
  #initializing regression model
  reg = Ridge(alpha = 0.5, normalize = True)
  
  #steps for pipeline
  steps = [('imputation',imp),('Ridge',reg)]
  
  #initializing pipeline
  pipeline = Pipeline(steps)
  
  #target and feature variables
  X = model_data.drop('life', axis = 1)
  y = model_data.loc[:,'life']
  
  #splitting into training and test
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 42)
  
  pipeline.fit(X_train, y_train)
  </code></pre>
  
  <p>The original data does contain a lot of NaN values, which is why the imputer is in place. However, the follow error is output after the code is executed: </p>
  
  <pre><code>Input contains NaN, infinity or a value too large for dtype('float64')
  </code></pre>
  
  <p>Which indicates that there are still NaNs in the data, despite the presence of the imputer. Any idea why this is happening?</p>