【问题标题】:Getting rid of the extra header row for HTML styling of Pandas multi-index DataFrames [duplicate]摆脱 Pandas 多索引 DataFrame 的 HTML 样式的额外标题行 [重复]
【发布时间】:2018-10-22 04:23:08
【问题描述】:

这个熊猫代码:

import pandas as pd
df=pd.DataFrame([[0,0,1,2,3],[0,1,3,4,5],[1,0,4,5,6],[1,1,5,6,7]],
            columns=['A','B','X','Y','Z'])
df.set_index(['A','B'], inplace=True)
df

在IPython Notebook中显示如下:

注意有两个标题行,用来区分索引列和数据列。

有没有办法让这些只显示在一个标题行中?

【问题讨论】:

  • grrr,我有这种似曾相识的感觉,知道我以前问过这个但找不到。

标签: python pandas jupyter-notebook


【解决方案1】:

只需使用,列名也在set_index:

df.set_index(['A','B','X','Y','Z'], inplace=True)
df

【讨论】:

  • 我不想那样做。请注意,它将所有数据值以粗体显示(<th> 单元格而不是 <td>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-17
  • 1970-01-01
  • 2019-12-31
  • 1970-01-01
  • 2018-03-19
相关资源
最近更新 更多