How to append a dataframe to existing excel sheet?
<p>The function gets called several times. I have kept a count so that if its called for the first time, A workbook is created. Then I write to that workbook using <code>pd.ExcelWrite()</code>. Next time <code>else:</code> gets executed and the same workbook is opened. Its first sheet is selected, its last row is found. And DataFrame is written on that row.
This is my code:</p>

<pre><code>def WriteFile (df):
  if count1 == 1:
      workbook = xlsxwriter.Workbook('pandas_simple.xlsx')
      writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
      df.to_excel(writer, index=False )
      workbook.close()
  else:
      book = open_workbook('pandas_simple.xlsx')
      sheet_names = book.sheet_names()
      sheet = book.sheet_by_name(sheet_names[0])
      row = sheet.nrows
      writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
      df.to_excel(writer, index=False, header=False, startrow = row )
</code></pre>

<p>I get this exception:</p>

<pre><code>Exception Exception: Exception('Exception caught in workbook destructor. Explicit close() 
may be required for workbook.',) in &lt;bound method Workbook.__del__ of &lt;xlsxwriter.workbook.Workbook 
object at 0x000000000A143860&gt;&gt; ignored Exception
</code></pre>

<p>And my pandas_simple.xlsx is also empty after execution of code. What am I doing wrong? </p>