答案 0 :(得分:1)
在助手DataFrame和export to excel中创建样式:
df = pd.DataFrame({'Date1':['19/3/2011','15/5/2015','18/8/2018'],
'Date2':['19/3/2011','1/1/2019','18/8/2018']})
print (df)
Date1 Date2
0 19/3/2011 19/3/2011
1 15/5/2015 1/1/2019
2 18/8/2018 18/8/2018
def highlight_diff(x):
c1 = 'background-color: red'
c2 = ''
m = x['Date1'] != x['Date2']
df1 = pd.DataFrame(c2, index=x.index, columns=x.columns)
df1.loc[m, :] = c1
return df1
(df.style
.apply(highlight_diff,axis=None)
.to_excel('styled.xlsx', engine='openpyxl', index=False))
答案 1 :(得分:1)
您应使用DataFrame.style
和DataFrame.to_excel
:
import pandas as pd
df = pd.DataFrame({'Date1':['19/3/2011','15/5/2015','18/8/2018'],
'Date2':['19/3/2011','1/1/2019','18/8/2018']})
df.style.apply(lambda x: ['background-color: red']*df.shape[1] if x['Date1'] != x['Date2'] else ['']*df.shape[1], axis=1).to_excel("output.xlsx", index=False)
您会得到:
答案 2 :(得分:1)
使用功能更简洁
$(window).scroll(function() {
if ($(this).scrollTop() > 210) {
console.log("scrolling");
console.log($(this).scrollTop());
let tlSecond = new TimelineLite();
tlSecond.from("#fifth_load_group", 3, {
marginTop: "50px",
ease: Power4.easeOut,
opacity: 0
});
}
});
编辑1:如果只希望突出显示第二列,
def format_df(x):
if x.Date1 != x.Date2:
return ['background-color: red'] * len(x)
return [''] * len(x)
df.style.apply(lambda x: format_df(x), axis=1).to_excel("file.xlsx",index=False)