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")
posted @ 2023-06-08 11:00  vx_guanchaoguo0  阅读(17)  评论(0编辑  收藏  举报