[英]Headers in to_latex
讓我們假設我有一個數據幀potential
,根據角度有一些能量:
121.7352 -3686.7807696787
105 -3686.6995320774
110 -3686.7274964541
115 -3686.6904245431
120 -3686.7741522700
125 -3686.7919721470
130 -3686.8060341619
135 -3686.8165389535
列標題是['angle', 'energy']
。
現在我想將其導出到 LaTeX 表中:
potential.to_latex('potential.tex', index = False)
如何在導出的表中獲取列標題,例如:
['Angle in $^\\circ$', 'Energy in kJ / mole']
請注意,我知道我可以在導出之前重命名potential
數據幀的列,然后將它們重命名。 但如果沒有必要,我不想這樣做。
pandas 接受包含列別名的可選header
參數:
aliases = ['Angle in $^\\circ$', 'Energy in kJ / mole']
potential.to_latex('potential.tex', index=False,
header=aliases)
to_string
方法也是如此。
您可以為此使用制表。
例如
>>> table = [["spam",42],["eggs",451],["bacon",0]]
>>> headers = ["item", "qty"]
>>> print tabulate(table, headers, tablefmt="simple")
item qty
------ -----
spam 42
eggs 451
bacon 0
您可以將tablefmt="latex"
作為參數傳遞以生成 Latex 表。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.