我有限制熊猫数据框行高的问题。
汉字有时简单地对齐为垂直线,这会扰乱视图。
我没有看到任何行高选项 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.set_option.html
有人可以建议一种修复视图的方法吗?
这可以使用
HTML
轻松完成,但我不确定你是否可以在 pandas 中做到这一点。例如,您可以将要显示的行数设置为 None
以显示所有行。这里有更多选项供您检查。
否则,使用
HTML
,可以这样做:
html = df.to_html()
html = html.replace('<tr>', '<tr style="height: 50px;">').replace('<td>', '<td style="width: 150px;">')
display(HTML(html))
您需要将宽度和高度调整为某些值,我不知道如何自动执行此操作。您将需要以下进口:
from IPython.display import display, HTML
之前显示的结果与
display(df)
:
之后,与
display(HTML(html))
: