【问题标题】:Remove index when writing a dataframe to tex file [duplicate]将数据框写入tex文件时删除索引[重复]
【发布时间】:2018-03-11 10:34:59
【问题描述】:

我有一个使用 pd.ExcelFile() 读取的数据框

我正在做这样的事情:

xl = pd.ExcelFile('input.xlsx')
df = pd.parse()
latexFormat = df.to_latex()

现在我将 latexFormat 写入 .tex 文件,只需以写入模式打开文件,然后执行 fid.write(latexFormat) 但它也包括索引。

如何在将索引写入 tex 文件时删除索引(或)在使用 to_latex() 之前我需要对 dataFrame 进行更改

【问题讨论】:

    标签: python pandas latex


    【解决方案1】:

    添加index=False,例如,

    latexFormat = df.to_latex(index=False)
    

    希望这会有所帮助。

    【讨论】:

    • 实际上我在一列数据框中的数字在 $10^{26}$ 的范围内。我想将它们写为 .tex 格式的字符串。像 10e+12。我该怎么做?
    • 您可以使用字符串格式来归档它。例如,'{.2e}'.format(1e12) 将输出 '1.00e+12'
    【解决方案2】:

    需要使用参数index=False

    latexFormat = df.to_latex(index=False)
    

    【讨论】:

      猜你喜欢
      • 2018-06-30
      • 2016-01-20
      • 2016-02-16
      • 2022-01-05
      • 1970-01-01
      • 2021-03-22
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多