title: TypeError: float() argument must be a string or a number, not 'function' – Python/Sklearn
body: <p>I have the following code snippet from a program called Flights.py</p>
  
  <pre><code>...
  #Load the Dataset
  df = dataset
  df.isnull().any()
  df = df.fillna(lambda x: x.median())
  
  # Define X and Y
  X = df.iloc[:, 2:124].values
  y = df.iloc[:, 136].values
  X_tolist = X.tolist()
  
  # Splitting the dataset into the Training set and Test set
  from sklearn.cross_validation import train_test_split
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
  
  # Feature Scaling
  from sklearn.preprocessing import StandardScaler
  sc = StandardScaler()
  X_train = sc.fit_transform(X_train)
  X_test = sc.transform(X_test)
  </code></pre>
  
  <p>The second to last line is throwing the following error:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-14-d4add2ccf5ab&gt;", line 3, in &lt;module&gt;
      X_train = sc.fit_transform(X_train)
  
    File "/Users/&lt;username&gt;/anaconda/lib/python3.6/site-packages/sklearn/base.py", line 494, in fit_transform
      return self.fit(X, **fit_params).transform(X)
  
    File "/Users/&lt;username&gt;/anaconda/lib/python3.6/site-packages/sklearn/preprocessing/data.py", line 560, in fit
      return self.partial_fit(X, y)
  
    File "/Users/&lt;username&gt;/anaconda/lib/python3.6/site-packages/sklearn/preprocessing/data.py", line 583, in partial_fit
      estimator=self, dtype=FLOAT_DTYPES)
  
    File "/Users/&lt;username&gt;/anaconda/lib/python3.6/site-packages/sklearn/utils/validation.py", line 382, in check_array
      array = np.array(array, dtype=dtype, order=order, copy=copy)
  
  TypeError: float() argument must be a string or a number, not 'function'
  </code></pre>
  
  <p>My dataframe <code>df</code> is of size (22587, 138)</p>
  
  <p>I was taking a look at the following question for inspiration:</p>
  
  <p><a href="https://stackoverflow.com/questions/43579753/typeerror-float-argument-must-be-a-string-or-a-number-not-method-in-geocod">TypeError: float() argument must be a string or a number, not &#39;method&#39; in Geocoder</a></p>
  
  <p>I tried the following adjustment:</p>
  
  <pre><code># Feature Scaling
  from sklearn.preprocessing import StandardScaler
  sc = StandardScaler()
  X_train = sc.fit_transform(X_train.as_matrix)
  X_test = sc.transform(X_test.as_matrix)
  </code></pre>
  
  <p>Which resulted in the following error:</p>
  
  <pre><code>AttributeError: 'numpy.ndarray' object has no attribute 'as_matrix'
  </code></pre>
  
  <p>I'm currently at a loss for how to scan thru the dataframe and find/convert the offending entries. </p>