Home > OS >  how to delete rows from excel who has red background color using python
how to delete rows from excel who has red background color using python

Time:03-22

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)

CodePudding user response:

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

  • Related