pands 给excel固定行着色
原来的excel
更换底色后的
全局换地底色
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,100,40).reshape(10,4))
df.style.applymap(lambda x:'background-color:red' if x%2 else "background-color:yellow").to_excel("test.xlsx")
单独的行换色
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,100,40).reshape(10,4))
df.style.applymap(lambda x:'background-color:red' if x%2 else "background-color:yellow",subset = pd.IndexSlice[:, ['B', 'C']])).to_excel("test.xlsx")
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17465600.html