Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

521
Views
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 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!