漂亮地打印Python Pandas Dataframe,没有标题和索引

问题描述 投票:0回答:1

我正在尝试漂亮地打印没有标题和索引的 Pandas 数据框,但没有成功

这打印得很漂亮,但也打印标题和索引

import pandas as pd
from IPython.display import display

data=pd.DataFrame(same_data)
display(data)

enter image description here


这会删除索引(不是标题),但不会漂亮地打印

import pandas as pd
from IPython.display import display, Markdown

data=pd.DataFrame(same_data)
display(Markdown(data.to_markdown(index=False)))

enter image description here

我做错了什么?

pandas jupyter-notebook ipython
1个回答
0
投票

对于那些遇到同样问题的人,这就是我最终解决的方法

import pandas as pd
from IPython.display import display, HTML

display(HTML(
    ref_signs_table.to_html(
        index=False, 
        header=False, 
        notebook=True
    ).replace('<td>', '<td align="right">')
))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.