title: Converting pandas.DataFrame to bytes
body: <p>I need convert the data stored in a <code>pandas.DataFrame</code> into a byte string where each column can have a separate data type (integer or floating point).  Here is a simple set of data:</p>
  
  <pre><code>df = pd.DataFrame([ 10, 15, 20], dtype='u1', columns=['a'])
  df['b'] = np.array([np.iinfo('u8').max, 230498234019, 32094812309], dtype='u8')
  df['c'] = np.array([1.324e10, 3.14159, 234.1341], dtype='f8')
  </code></pre>
  
  <p>and df looks something like this:</p>
  
  <pre><code>    a            b                  c
  0   10  18446744073709551615    1.324000e+10
  1   15  230498234019            3.141590e+00
  2   20  32094812309             2.341341e+02
  </code></pre>
  
  <p>The <code>DataFrame</code> knows about the types of each column <code>df.dtypes</code> so I'd like to do something like this:</p>
  
  <pre><code>data_to_pack = [tuple(record) for _, record in df.iterrows()]
  data_array = np.array(data_to_pack, dtype=zip(df.columns, df.dtypes))
  data_bytes = data_array.tostring()
  </code></pre>
  
  <p>This typically works fine but in this case (due to the maximum value stored in <code>df['b'][0]</code>.  The second line above converting the array of tuples to an <code>np.array</code> with a given set of types causes the following error:</p>
  
  <pre><code>OverflowError: Python int too large to convert to C long
  </code></pre>
  
  <p>The error results (I believe) in the first line which extracts the record as a <code>Series</code> with a single data type (defaults to <code>float64</code>)  and the representation chosen in <code>float64</code> for the maximum <code>uint64</code> value is not directly convertible back to <code>uint64</code>.  </p>
  
  <p>1) Since the <code>DataFrame</code> already knows the types of each column is there a way to get around creating a row of tuples for input into the typed <code>numpy.array</code> constructor?  Or is there a better way than outlined above to preserve the type information in such a conversion?</p>
  
  <p>2) Is there a way to go directly from <code>DataFrame</code> to a byte string representing the data using the type information for each column.</p>