• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

421
Vistas
Making Multi-row work in pandas dataframe.to_latex()

I have the following dataframe:

      dataset Baseline       Version2      
               F-1   F-2      F-1   F-2
0       G    0.971 0.967    0.971 0.967
1       H    0.780 0.762    0.800 0.777
2       S    0.401 0.320    0.453 0.365
3       T    0.881 0.825    0.989 0.985

My goal is to export this to LaTeX, which I do by pandas.DataFrame.to_latex():

latex = df.to_latex(
        index=False,
        escape=False,
        sparsify=True,
        multirow=True,
        multicolumn=True,
        multicolumn_format='c',
        position='H'
    )

obtaining the following code in LaTeX:

\begin{table}[H]
\centering
\begin{tabular}{lrrrr}
\toprule
dataset & \multicolumn{2}{c}{Baseline} & \multicolumn{2}{c}{Version2} \\
        &      F-1 &   F-2 &      F-1 &   F-2 \\
\midrule
      G &    0.971 & 0.967 &    0.971 & 0.967 \\
      H &    0.780 & 0.762 &    0.800 & 0.777 \\
      S &    0.401 & 0.320 &    0.453 & 0.365 \\
      T &    0.881 & 0.825 &    0.989 & 0.985 \\
\bottomrule
\end{tabular}
\end{table}

which is rendered like this: enter image description here My issue is: I'd expect a multirow to appear in the "dataset", covering the 2 lines with "dataset" and "", like this: enter image description here I have multirow=True in the options, but I can't make this work. Any idea on how can I fix this?

over 3 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda