Python| Pandas DataFrame.to_latex() 方法
在DataFrame.to_latex()
方法的帮助下,我们可以通过DataFrame.to_latex()
() 方法以乳胶文档的形式获取数据帧,我们可以将其作为单独的文件打开。
Syntax : DataFrame.to_latex()
Return : Return the dataframe as a latex document.
示例 #1:
在这个例子中,我们可以说通过使用DataFrame.to_latex()
方法,我们能够以乳胶文档的形式获取数据帧。
# import DataFrame
import pandas as pd
# using DataFrame.to_latex() method
gfg = pd.DataFrame({'Name': ['Marks'],
'Jitender': ['78'],
'Rahul': ['77.9']})
print(gfg.to_latex(index = True, multirow = True))
输出 :
\begin{tabular}{llll}
\toprule
{} & Name & Jitender & Rahul \\
\midrule
0 & Marks & 78 & 77.9 \\
\bottomrule
\end{tabular}
示例 #2:
# import DataFrame
import pandas as pd
# using DataFrame.to_latex() method
gfg = pd.DataFrame({'Name': ['Marks', 'Gender'],
'Jitender': ['78', 'Male'],
'Purnima': ['78.9', 'Female']})
print(gfg.to_latex(index = False, multirow = True))
输出 :
\begin{tabular}{lll}
\toprule
Name & Jitender & Purnima \\
\midrule
Marks & 78 & 78.9 \\
Gender & Male & Female \\
\bottomrule
\end{tabular}