coloring cells in excel with pandas
<p>I need some help here. So i have something like this </p>

<pre><code>import pandas as pd
path = '/Users/arronteb/Desktop/excel/ejemplo.xlsx'
xlsx = pd.ExcelFile(path)
df = pd.read_excel(xlsx,'Sheet1')
df['is_duplicated'] = df.duplicated('#CSR')
df_nodup = df.loc[df['is_duplicated'] == False]
df_nodup.to_excel('ejemplo.xlsx', encoding='utf-8')
</code></pre>

<p>So basically this program load the <code>ejemplo.xlsx</code> (ejemplo is example in Spanish, just the name of the file) into <code>df</code> (a <code>DataFrame</code>), then checks for duplicate values in a specific columnââ. It deletes the duplicates and saves the file again. That part works correctly. The problem is that instead of removing duplicates, I need highlight the cells containing them with a different color, like yellow.</p>

<p>You can create a function to do the highlighting...</p>

<pre><code>def highlight_cells():
    # provide your criteria for highlighting the cells here
    return ['background-color: yellow']
</code></pre>

<p>And then apply your highlighting function to your dataframe...</p>

<pre><code>df.style.apply(highlight_cells)
</code></pre>

python excel pandas duplicates highlight