데이터프레임이 있고, 이를 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() 함수를 적용하고, index와 multirow 매개변수를 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}