title: Convert Pandas DataFrame to bytes-like object
body: <p>Hi I am trying to convert my df to binary and store it in a variable.</p>
  <p>my_df:</p>
  <pre><code> df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
  </code></pre>
  <p>my code:</p>
  <pre><code> import io
   towrite = io.BytesIO()
   df.to_excel(towrite)  # write to BytesIO buffer
   towrite.seek(0)  # reset pointer
   
  </code></pre>
  <p>I am getting <code>AttributeError: '_io.BytesIO' object has no attribute 'write_cells'</code></p>
  <p>Full Traceback:</p>
  <pre><code>AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-25-be6ee9d9ede6&gt; in &lt;module&gt;()
        1 towrite = io.BytesIO()
  ----&gt; 2 df.to_excel(towrite)  # write to BytesIO buffer
        3 towrite.seek(0)  # reset pointer
        4 encoded = base64.b64encode(towrite.read())  #
  
  C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, encoding, inf_rep, verbose, freeze_panes)
     1422         formatter.write(excel_writer, sheet_name=sheet_name, startrow=startrow,
     1423                         startcol=startcol, freeze_panes=freeze_panes,
  -&gt; 1424                         engine=engine)
     1425 
     1426     def to_stata(self, fname, convert_dates=None, write_index=True,
  
  C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\formats\excel.py in write(self, writer, sheet_name, startrow, startcol, freeze_panes, engine)
      624 
      625         formatted_cells = self.get_formatted_cells()
  --&gt; 626         writer.write_cells(formatted_cells, sheet_name,
      627                            startrow=startrow, startcol=startcol,
      628                            freeze_panes=freeze_panes)
  
  AttributeError: '_io.BytesIO' object has no attribute 'write_cells'
  </code></pre>