다음과 같이 라텍스로 변환된 데이터 프레임과 결과가 있다고 가정합니다.
\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}