title: Modify an Excel file with Pandas, with minimal change of the layout
body: <p>I've already read <a href="https://stackoverflow.com/questions/28142420/can-pandas-read-and-modify-a-single-excel-file-worksheet-tab-without-modifying">Can Pandas read and modify a single Excel file worksheet (tab) without modifying the rest of the file?</a> but here my question is specific to the layout mentioned hereafter.</p>
  <p><strong>How to open an Excel file with Pandas, do some modifications, and save it back:</strong></p>
  <ul>
  <li><p>(1) without removing that there is a <code>Filter</code> on the first row</p>
  <p><a href="https://i.stack.imgur.com/geIst.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/geIst.png" alt="enter image description here" /></a></p>
  </li>
  <li><p>(2) without modifying the &quot;displayed column width&quot; of the columns as displayed in Excel</p>
  </li>
  <li><p>(3) without removing the formulas which might be present on some cells</p>
  </li>
  </ul>
  <p><strong>?</strong></p>
  <p>Here is what I tried, it's a short example (in reality I do more processing with Pandas):</p>
  <pre><code>import pandas as pd
  
  df = pd.read_excel('in.xlsx')
  df['AB'] = df['A'].astype(str) + ' ' + df['B'].astype(str)  # create a new column from 2 others
  del df['Date']                                              # delete columns
  del df['Time']
  df.to_excel('out.xlsx', index=False)
  </code></pre>
  <p>With this code, the <code>Filter</code> of the first row is removed and the displayed column width are set to a default, which is not very handy (because we would have to manually set the correct width for all columns).</p>