title: Exporting pandas table as pdf
body: <p>I found quite a nice way to export a table generated with <code>pandas</code> <a href="https://stackoverflow.com/questions/26678467/export-a-pandas-dataframe-as-a-table-image">here</a> to PDF, the part about converting it to a png file is uninteresting to me.</p>
  
  <p>The problem is, that I get the following error message:</p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-10-9818a71c26bb&gt; in &lt;module&gt;()
       13 
       14 with open(filename, 'wb') as f:
  ---&gt; 15     f.write(template.format(z.to_latex()))
       16 
       17 subprocess.call(['pdflatex', filename])
  
  TypeError: a bytes-like object is required, not 'str'
  </code></pre>
  
  <p>I'm not really understanding the code in the first place which makes it quite hard to correct the error. My code looks like this:</p>
  
  <pre><code>import subprocess
  
  filename = 'out.tex'
  pdffile = 'out.pdf'
  
  template = r'''\documentclass[preview]{{standalone}}
  \usepackage{{booktabs}}
  \begin{{document}}
  {}
  \end{{document}}
  '''
  
  with open(filename, 'wb') as f:
      f.write(template.format(z.to_latex()))
  
  subprocess.call(['pdflatex', filename])
  </code></pre>
  
  <p>where <code>z</code> is a <code>DataFrame</code> generated with <code>pandas</code>.</p>
  
  <p>Hope someone can help out.
  Thank you in advance,
  Sito.</p>