How to keep column names when converting from pandas to numpy
<p>According <a href="https://stackoverflow.com/questions/7561017/get-the-column-names-of-a-python-numpy-ndarray">to this post</a>, I should be able to access the names of columns in an ndarray as a.dtype.names</p>

<p>Howevever, if I convert a pandas DataFrame to an ndarray with df.as_matrix() or df.values, then the dtype.names field is None. Additionally, if I try to assign column names to the ndarray</p>

<pre><code>X = pd.DataFrame(dict(age=[40., 50., 60.], sys_blood_pressure=[140.,150.,160.]))
print X
print type(X.as_matrix())# &lt;type 'numpy.ndarray'&gt;
print type(X.as_matrix()[0]) # &lt;type 'numpy.ndarray'&gt;

m = X.as_matrix()
m.dtype.names = list(X.columns)
</code></pre>

<p>I get</p>

<pre><code>ValueError: there are no fields defined
</code></pre>

<p>UPDATE:</p>

<p>I'm particularly interested in the cases where the matrix only needs to hold a single type (it is an ndarray of a specific numeric type), since I'd also like to use cython for optimization. (I suspect numpy records and structured arrays are more difficult to deal with since they're more freely typed.)</p>

<p>Really, I'd just like to maintain the column_name meta data for arrays passed through a deep tree of sci-kit predictors. Its interface's .fit(X,y) and .predict(X) API don't permit passing additional meta-data about the column labels outside of the X and y object.</p>