Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <code>to_records</code> method, but have to play around a bit with the dtypes if they are not what you want from the get go. In my case, having copied your DF from a string, the index type is string (represented by an <code>object</code> dtype in pandas):</p> <pre><code>In [102]: df Out[102]: 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 In [103]: df.index.dtype Out[103]: dtype('object') In [104]: df.to_records() Out[104]: rec.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=[('index', '|O8'), ('A', '&lt;f8'), ('B', '&lt;f8'), ('C', '&lt;f8')]) In [106]: df.to_records().dtype Out[106]: dtype([('index', '|O8'), ('A', '&lt;f8'), ('B', '&lt;f8'), ('C', '&lt;f8')]) </code></pre> <p>Converting the recarray dtype does not work for me, but one can do this in Pandas already:</p> <pre><code>In [109]: df.index = df.index.astype('i8') In [111]: df.to_records().view([('ID', '&lt;i8'), ('A', '&lt;f8'), ('B', '&lt;f8'), ('C', '&lt;f8')]) Out[111]: rec.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;i8'), ('A', '&lt;f8'), ('B', '&lt;f8'), ('C', '&lt;f8')]) </code></pre> <p>Note that Pandas does not set the name of the index properly (to <code>ID</code>) in the exported record array (a bug?), so we profit from the type conversion to also correct for that. </p> <p>At the moment Pandas has only 8-byte integers, <code>i8</code>, and floats, <code>f8</code> (see this <a href="https://github.com/pydata/pandas/issues/622">issue</a>).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload