title: Convert heterogeneous pandas.DataFrame to homogeneous one
body: <p>I want to analyse <strong>heterogeneous</strong> data in the form <em>observations</em>/<em>variables</em> contained in a <code>pandas.DataFrame</code> like this:</p>
  
  <pre><code>   Age   Name     Ok  Result
  0   25    Bob   True     1.2
  1   41   John  False     0.5
  2   30  Alice   True     0.3
  </code></pre>
  
  <p>For that, I usually convert it to its <code>Numpy</code> representation using <code>pandas.DataFrame.values</code>, thus obtaining:</p>
  
  <pre><code>[[25 'Bob'   True  1.2]
   [41 'John'  False 0.5]
   [30 'Alice' True  0.3]]
  </code></pre>
  
  <p>which includes only <code>object</code> type if I understand correctly the documentation:</p>
  
  <blockquote>
    <p>A DataFrame with mixed type columns(e.g., str/object, int64, float32) results in an ndarray of the broadest type that accommodates these mixed types (e.g., object).</p>
  </blockquote>
  
  <p><strong>Question</strong>: How to convert a <code>pandas.DataFrame</code> (or a <code>numpy.ndarray</code>) of heterogeneous type to a one with homogeneous numeric type like this:</p>
  
  <pre><code>[[25.0  1.0  1.0  1.2]
   [41.0  2.0  0.0  0.5]
   [30.0  3.0  1.0  0.3]]
  </code></pre>
  
  <p>where there is a correspondance between <code>'Bob'</code> and <code>1.0</code>, <code>'John'</code> and <code>2.0</code> ... <code>True</code> and <code>1.0</code> ...</p>
  
  <p>I ask this because I want to perform a <code>sklearn.decomposition.PCA</code> on <em>all</em> the data, which produces error when dealing with string values.</p>
  
  <hr>
  
  <p>Here is a minimal (<em>not</em>) working example : </p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from sklearn.decomposition import PCA
  
  d  = {'Name': ['Bob', 'John', 'Alice'], 'Age': [25, 41, 30], 'Result' : [1.2, 0.5, 0.3], 'Ok' : [True, False, True]}
  df = pd.DataFrame(data=d)
  
  df.info()
  print(df)
  
  data = df.values
  
  print(data)
  
  pca = PCA(n_components=all)
  pca.fit(data)
  </code></pre>