title: Convert pandas dataframe to NumPy array
body: <p>How do I convert a pandas dataframe into a NumPy array?</p>
  <p>DataFrame:</p>
  <pre><code>import numpy as np
  import pandas as pd
  
  index = [1, 2, 3, 4, 5, 6, 7]
  a = [np.nan, np.nan, np.nan, 0.1, 0.1, 0.1, 0.1]
  b = [0.2, np.nan, 0.2, 0.2, 0.2, np.nan, np.nan]
  c = [np.nan, 0.5, 0.5, np.nan, 0.5, 0.5, np.nan]
  df = pd.DataFrame({'A': a, 'B': b, 'C': c}, index=index)
  df = df.rename_axis('ID')
  </code></pre>
  <p>gives</p>
  <pre><code>label   A    B    C
  ID                                 
  1   NaN  0.2  NaN
  2   NaN  NaN  0.5
  3   NaN  0.2  0.5
  4   0.1  0.2  NaN
  5   0.1  0.2  0.5
  6   0.1  NaN  0.5
  7   0.1  NaN  NaN
  </code></pre>
  <p>I would like to convert this to a NumPy array, like so:</p>
  <pre><code>array([[ nan,  0.2,  nan],
         [ nan,  nan,  0.5],
         [ nan,  0.2,  0.5],
         [ 0.1,  0.2,  nan],
         [ 0.1,  0.2,  0.5],
         [ 0.1,  nan,  0.5],
         [ 0.1,  nan,  nan]])
  </code></pre>
  <hr />
  <p>Also, is it possible to preserve the dtypes, like this?</p>
  <pre><code>array([[ 1, nan,  0.2,  nan],
         [ 2, nan,  nan,  0.5],
         [ 3, nan,  0.2,  0.5],
         [ 4, 0.1,  0.2,  nan],
         [ 5, 0.1,  0.2,  0.5],
         [ 6, 0.1,  nan,  0.5],
         [ 7, 0.1,  nan,  nan]],
       dtype=[('ID', '&lt;i4'), ('A', '&lt;f8'), ('B', '&lt;f8'), ('B', '&lt;f8')])
  </code></pre>