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:
no_red.xlsx:
More than one column input:
Output: