这是使红色标记的每列中的最大值的代码.
import pandas as pd
def highlight_max(s):
'''
highlight the maximum in a Series yellow.
'''
is_max = s == s.max()
return ['color: red' if v else '' for v in is_max]
writer = pd.ExcelWriter(f"after.xlsx", engine="xlsxwriter")
df = pd.read_excel('test.xlsx')
df.style.apply(highlight_max).to_excel(writer, index=False)
writer.save()
如何优化代码,使每列的前三个数据都用红色标记?