title: How to write dataframe to excel with conditional formatting in Python?
body: <p>How to export pandas dataframe to excel with conditional formatting?</p>
  <p><strong>Sample Data</strong></p>
  <pre><code>from random import randint
  
  x = [randint(0, 1) for p in range(0, 10)]
  
  sample_dict = {&quot;Col1&quot;: [randint(0, 1) for p in range(0, 10)],
                 &quot;Col2&quot;: [randint(0, 1) for p in range(0, 10)],
                 &quot;Col3&quot;: [randint(0, 1) for p in range(0, 10)],
                 &quot;Col4&quot;: [randint(0, 1) for p in range(0, 10)],
                 &quot;Col5&quot;: [randint(0, 1) for p in range(0, 10)],
                 &quot;Col6&quot;: [randint(0, 1) for p in range(0, 10)]}
  
  sample = pd.DataFrame(sample_dict)
  </code></pre>
  <pre><code>
    Col1  Col2    Col3    Col4    Col5    Col6
  0   1   1   0   1   0   0
  1   0   1   1   0   1   1
  2   1   0   1   0   0   1
  3   1   1   0   1   0   0
  4   1   0   0   1   1   1
  5   0   0   1   1   0   0
  6   1   1   0   0   0   0
  7   0   0   1   0   1   1
  8   0   1   1   1   0   0
  9   0   1   1   0   0   1
  </code></pre>
  <p>Required Conditional Formatting in pandas styler</p>
  <pre><code>sample.style.apply(lambda x: [&quot;background: orange&quot; if v != x.iloc[0] else &quot;&quot; for v in x], axis = 1)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/du0MP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/du0MP.jpg" alt="enter image description here" /></a></p>