gpt4 book ai didi

Format Pandas DataFrame to Excel - Index Names(将Pandas DataFrame格式化为Excel-索引名称)

转载 作者:bug小助手 更新时间:2023-10-25 15:57:34 25 4
gpt4 key购买 nike



How can I specify the format to Index Names using df.style method? I was hoping that there was something like apply_map_index_name but I don't believe there is.

如何使用df.style方法指定索引名称的格式?我希望有像APPLY_MAP_INDEX_NAME这样的东西,但我不相信有这样的东西。


Thanks in advance

提前谢谢你


更多回答

this may help

这可能会有帮助

It does not unfortunately as it just changes the index labels

不幸的是,它不会,因为它只是更改了索引标签

优秀答案推荐

That's an open issue (see GH48936, that is yours).

这是一个悬而未决的问题(参见GH48936,这是您的)。


As a workaround, you can use CSS selectors with set_table_styles (which is not Excel-friendly) :

作为一种解决办法,您可以将CSS选择器与SET_TABLE_STYLES一起使用(这对Excel不友好):


df = pd.DataFrame(np.random.randn(5, 5), columns=list("ABCDE"))

d1 = {
"selector": ".index_name:before",
"props": """content:'stack'; font-weight:lighter;
color:white;background-color:#f48024"""
}

d2 = {
"selector": ".index_name:after",
"props": "content:'overflow'; font-weight:bold"
}

df.rename_axis("").style.set_table_styles([d1, d2]).pipe(display)

Output :

输出:


enter image description here


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com