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
提前谢谢你
更多回答
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 :
输出:
更多回答
我是一名优秀的程序员,十分优秀!