'how to delete rows from excel who has red background color using python

read_file.style.apply(lambda x: [ 'background-color:%s' % 'red' if x < y else 'background-color :%s' % 'green' for x in read_file.language], axis=0 ,inplace=True) print("done") read_file.to_excel('coloured.xlsx',engine='openpyxl', index=False)



Solution 1:[1]

Use:

import openpyxl
from openpyxl import load_workbook
excel_file = 'color.xlsx' 
wb = load_workbook(excel_file, data_only = True)
sh = wb['Sheet1']

out = []
for row in sh:
    if row[0].fill.start_color.index == '00000000':
        out.append([row[i].value for i in range(len(row))])
        
pd.DataFrame(out).to_excel('no_red.xlsx')
        

color.xlsx:

enter image description here

no_red.xlsx:

enter image description here

More than one column input:

enter image description here

Output:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1