Python | Pandas DataFrame.to_latex() method

With the help of DataFrame.to_latex() method, We can get the dataframe in the form of latex document which we can open as a separate file by using DataFrame.to_latex() method.

Syntax : DataFrame.to_latex()
Return : Return the dataframe as a latex document.

Example #1 :
In this example we can say that by using DataFrame.to_latex() method, we are able to get the dataframe in the form latex document.



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output :

\begin{tabular}{llll}
\toprule
{} & Name & Jitender & Rahul \\
\midrule
0 & Marks & 78 & 77.9 \\
\bottomrule
\end{tabular}

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output :

\begin{tabular}{lll}
\toprule
Name & Jitender & Purnima \\
\midrule
Marks & 78 & 78.9 \\
Gender & Male & Female \\
\bottomrule
\end{tabular}



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.