【发布时间】:2020-11-09 21:35:27
【问题描述】:
我想从 pandas Styler 中删除标题,以便我可以渲染它。 我尝试过的:
def highlight(x):
c1 = 'background-color: #f5f5dc'
df1 = pd.DataFrame('', index=x.index, columns=x.columns)
df1.loc[['A'], :] = c1
return df1
temp = {'col1': ['abc', 'def'], 'col2': [1.0, 2.0]}
df = pd.DataFrame(temp)
df.index = ['A', 'B']
print(df)
df.style.apply(highlight, axis=None).hide_index()
输出
col1 col2
-------------
abc 1.000000
def 2.000000
但我想删除 col1 和 col2,因为它出现在我不需要的渲染后页面中。
有什么办法可以做到吗?
【问题讨论】:
标签: python-3.x pandas pandas-styles