You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

写入LaTeX格式时DataFrame输出形状为何改变?

问题:DataFrame中LaTeX格式导致表格形状异常

当我尝试为DataFrame的Function列3个元素全部采用LaTeX格式编写时,仅前两个元素使用LaTeX格式才能保证输出形状不发生变化。以下是不同的测试结果:

测试1:全部元素使用LaTeX格式

error = (pd.DataFrame({'Function': [
        '$ f_0(x) = 1 $', 
        '$ f_1(x) = x $', 
        '$ f_2(x) = x^2 $'
    ], 
    'Error': [1, 2, 3]})
).style.set_table_styles([dict(selector = 'th', props = [('text-align', 'center')])])
error.set_properties(**{'text-align': 'center'}).hide_index()

输出1

测试2:仅前两个元素使用LaTeX格式

error = (pd.DataFrame({'Function': [
        '$ f_0(x) = 1 $', 
        '$ f_1(x) = x $', 
        'f_2(x) = x^2'
    ], 
    'Error': [1, 2, 3]})
).style.set_table_styles([dict(selector = 'th', props = [('text-align', 'center')])])
error.set_properties(**{'text-align': 'center'}).hide_index()

输出2

内容的提问来源于stack exchange,提问作者user24835356

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 17:05:07