data = [{'Way too long of a column to be reasonable':4,'Four?':4},
{'Way too long of a column to be reasonable':5,'Four?':5}]
dfoo = pd.DataFrame(data)
dfoo.style.set_table_styles(
[dict(selector="th",props=[('max-width', '80px')]),
dict(selector="th.col_heading",
props=[("writing-mode", "vertical-rl"),
('transform', 'rotateZ(-90deg)'),
])]
)
from IPython.display import HTML, display
data = [{'Way too long of a column to be reasonable':4,'Four?':4},
{'Way too long of a column to be reasonable':5,'Four?':5}]
df = pd.DataFrame(data)
styles = [
dict(selector="th", props=[("font-size", "125%"),
("text-align", "center"),
("transform", "translate(0%,-30%) rotate(-5deg)")
]),
dict(selector=".row_heading, .blank", props= [('display', 'none;')])
]
html = df.style.set_table_styles(styles).render()
display(HTML(html))
import pandas as pd
from pybloqs import Block
import pybloqs.block.table_formatters as tf
from IPython.core.display import display, HTML
data = [{'Way too long of a column to be reasonable':4,'Four?':4},
{'Way too long of a column to be reasonable':5,'Four?':5}]
dfoo =pd.DataFrame(data)
fmt_header = tf.FmtHeader(fixed_width='5cm',index_width='10%',
top_padding='10cm', rotate_deg=60)
table_block = Block(dfoo, formatters=[fmt_header])
display(HTML(table_block.render_html()))
table_block.save('Table.html')
5条答案
按热度按时间h7appiyu1#
类似于:
可能接近你想要的:
see result here
ybzsozfc2#
查看pybloqs source code以获得可接受答案的解决方案,我能够找到如何在不安装pybloqs的情况下旋转柱。请注意,这也会旋转索引,但我添加了代码来删除这些内容。
ha5z0ras3#
我把@Bobain的好答案放到一个函数中,这样我就可以在整个笔记本中重复使用它。
ddhy6vgd4#
使用Python库'pybloqs'(http://pybloqs.readthedocs.io/en/latest/),可以旋转列名并在顶部添加填充。唯一的缺点(如文档所述)是顶部填充不能与Jupyter内联。必须导出该表。
x6yk4ghg5#
我可以让文本完全旋转90度,但不知道如何使用
text-orientation: upright
,因为它只是使文本不可见:(你错过了writing-mode
属性,必须设置text-orientation
才能有任何效果。另外,我通过对选择器进行一点修改,使其仅适用于列标题。dfoo.style.set_table_styles([dict(selector="th.col_heading",props=[("writing-mode", "vertical-lr"),('text-orientation', 'upright')])])
希望这能让你更接近你的目标!