मान लें, आपके पास एक डेटाफ्रेम है और LaTeX में बदलने का परिणाम:
\begin{tabular}{lrr}
\toprule
{} & Id & Age \\
\midrule
0 & 1 & 12 \\
1 & 2 & 13 \\
2 & 3 & 14 \\
3 & 4 & 15 \\
4 & 5 & 16 \\
\bottomrule
\end{tabular}
समाधान
इसे हल करने के लिए, हम नीचे दिए गए चरणों का पालन करेंगे:
एक डेटाफ्रेम परिभाषित करें
डेटाफ्रेम पर to_latex() फ़ंक्शन लागू करें और इंडेक्स और मल्टीरो मान को True पर सेट करें। इसे नीचे परिभाषित किया गया है:
df.to_latex(index=True, multirow=True)
उदाहरण
बेहतर समझ के लिए निम्न कोड देखें:
import pandas as pd
df = pd.DataFrame({'Id': [1,2,3,4,5], 'Age': [12,13,14,15,16]})
print(df.to_latex(index=True, multirow=True))
आउटपुट
\begin{tabular}{lrr}
\toprule
{} & Id & Age \\
\midrule
0 & 1 & 12 \\
1 & 2 & 13 \\
2 & 3 & 14 \\
3 & 4 & 15 \\
4 & 5 & 16 \\
\bottomrule
\end{tabular}