Dataframe 在Jupyter笔记本的列标题中显示带有数学符号的数据帧

Dataframe 在Jupyter笔记本的列标题中显示带有数学符号的数据帧,dataframe,matplotlib,latex,jupyter,multi-index,Dataframe,Matplotlib,Latex,Jupyter,Multi Index,我有一个数据框,我想用聚合函数的希腊名称来显示它 df=pd.DataFrame( [["A",1,2],["A",3,4],["B",5,6],["B",7,8]], columns=["AB","C", "N"] ) df=df.groupby(df.AB).agg({ "C":["count", "sum", "mean", "std"], "N":["sum", "mean", "std"] }) 这看起来像: 我想制作这样的东西:

我有一个数据框,我想用聚合函数的希腊名称来显示它

df=pd.DataFrame(
      [["A",1,2],["A",3,4],["B",5,6],["B",7,8]], 
      columns=["AB","C", "N"]
)
df=df.groupby(df.AB).agg({
     "C":["count", "sum", "mean", "std"], 
     "N":["sum", "mean", "std"]
})
这看起来像:

我想制作这样的东西:

我已经能够制作:

df.to_latex()的
df.to_latex()

多亏了下面的Elliot,类似这样的东西工作得非常好

substitutions = {
    "sum":"\u03a3",
    "mean":"\u03bc",
    "std":"\u03c3",
    True:"\u2705",
    False:"\u274c",
    "count":"N",
}

pretty = df.\
    rename(substitutions, axis=0).\
    rename(substitutions, axis=1)
以及:

%%HTML
<style type="text/css">
table.dataframe td, table.dataframe th {
    border: 1px  black solid !important;
  color: black !important;
}
th {
  text-align: center !important;
}
</style>
%%%HTML
table.dataframe td,table.dataframe th{
边框:1px黑色实心!重要;
颜色:黑色!重要;
}
th{
文本对齐:居中!重要;
}
能产生


您可以使用Unicode字符获取所需的字符标题,而无需费心使用
to_latex()

如果需要边框,可以使用
来设置html
格式来设置表格格式

%%HTML
<style type="text/css">
table.dataframe td, table.dataframe th {
    border: 1px  black solid !important;
  color: black !important;
}
th {
  text-align: center !important;
}
</style>