title: Can't set appropriate dtypes reading from a Numpy array
body: <p>I would like to save some attributes of a dataframe and given a slice of the underlying numpy array, I would like to rebuild the dataframe as if I had taken a slice of the dataframe. If an object column has a value that can be coerced into a float, I can't figure out any method that would work. In the real dataset, I have millions of observations and several hundred columns.</p>
  
  <p>The actual use case involves custom code where pandas interacts with scikit-learn. I know the latest build of scikit-learn has compatibility with pandas built in, but I am unable to use this version because the RandomizedSearchCV object cannot handle large parameter grids (this will be fixed in a future version).</p>
  
  <pre class="lang-py prettyprint-override"><code>data = [[2, 4, "Focus"],
          [3, 4, "Fiesta",],
          [1, 4, "300"],
          [7, 3, "Pinto"]]
  
  # This dataframe is exactly as intended
  df = pd.DataFrame(data=data)
  
  # Slice a subset of the underlying numpy array
  raw_slice = df.values[1:,:]
  
  # Try using the dtype option to force dtypes
  df_dtype = pd.DataFrame(data=raw_slice, dtype=df.dtypes)
  print "\n Dtype arg doesn't use passed dtypes \n", df_dtype.dtypes
  
  # Try converting objects to numeric after reading into dataframe
  df_convert = pd.DataFrame(data=raw_slice).convert_objects(convert_numeric=True)
  print "\n Convert objects drops object values that are not numeric \n", df_convert
  </code></pre>
  
  
  
  <pre><code>[Out]
   Converted data does not use passed dtypes 
  0    object
  1    object
  2    object
  dtype: object
  
   Converted data drops object values that are not numeric 
     0  1    2
  0  3  4  NaN
  1  1  4  300
  2  7  3  NaN
  </code></pre>
  
  <p>EDIT:
  Thank you @unutbu for the answer which precisely answered my question. In scikit-learn versions prior to 0.16.0, gridsearch objects stripped the underlying numpy array from the pandas dataframe. This meant that a single object column made the entire array an object and pandas methods could not be wrapped in custom transformers. </p>
  
  <p>The solution, using @unutbu's answer is to make the first step of the pipeline a custom "DataFrameTransformer" object.</p>
  
  <pre class="lang-py prettyprint-override"><code>class DataFrameTransformer(BaseEstimator, TransformerMixin):
      def __init__(self, X):
          self.columns = list(X.columns)
          self.dtypes = X.dtypes
  
      def fit(self, X, y=None):
          return self
  
      def transform(self, X, y=None):
          X = pd.DataFrame(X, columns=self.columns)
          for col, dtype in zip(X, self.dtypes):
              X[col] = X[col].astype(dtype)
          return X
  </code></pre>
  
  <p>In the pipeline, just include your original df in the constructor:</p>
  
  <pre><code>pipeline = Pipeline([("df_converter", DataFrameTransformer(X)),
                        ...,
                       ("rf", RandomForestClassifier())])
  </code></pre>