作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图用一个粗体栏返回 df.to_html()。我只试过
df = pd.DataFrame({'important_column': [1,2,3,4],
'dummy_column': [5,6,7,8]})
def some_function()
df.apply(lambda x: '<b>' + str(df['important_column']) + '</b>', axis=1)
return [df.to_html()]
但是好像不行。有人知道实用的解决方案吗?
最佳答案
您可以使用 df.style.set_properties
然后 .render()
这将为 .to_html()
的普通表输出添加前缀与适当的 style
元素。 (请注意,这不会将您的文本元素物理包装在 <b>
或 <strong>
或您想要的任何标签中,而是纯粹为这些单元格提供样式 - 根据用例,这可能是您想要的,也可能不是您想要的)
html = df.style.set_properties(
subset=['important_column'],
**{'font-weight': 'bold'}
).render()
(jupyter 笔记本中显示的示例)
关于python - pandas DataFrame to_html 中的粗体列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52110530/
下面是我用来制作 1px 文本描边轮廓的代码。但是如何使轮廓变粗呢?如果我只是用“5px”替换所有“1px”,结果看起来很疯狂。 HTML Hello! CSS .element { color:
我是一名优秀的程序员,十分优秀!