Python | Метод Pandas DataFrame.to_latex ()

Опубликовано: 27 Марта, 2022

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.

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

Выход :

egin{tabular}{llll}
oprule
{} & Name & Jitender & Rahul \
midrule
0 & Marks & 78 & 77.9 \
ottomrule
end{tabular}

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

Выход :

egin{tabular}{lll}
oprule
Name & Jitender & Purnima \
midrule
Marks & 78 & 78.9 \
Gender & Male & Female \
ottomrule
end{tabular}

Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.

Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.