Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

628
Vistas
Python tabulate: to have multiple header with merged cell

Is there a way to specify multiple headers with merged cells in python?

example dataset:

from tabulate import tabulate

cols = ["ID", "Config\nA", "Config\nB", "Config\nC", "Config\nD", "Oth"]
rows = [[ "0x0", "2", "0", "0", "4", "3"],
        [ "0x1", "0", "0", "0", "0", "4"],
        [ "0x2", "0", "2", "0", "1", "5"]]

print(tabulate(rows, headers=cols,tablefmt="pretty"))

current output from tabulate:

 +-----+--------+--------+--------+--------+--------+
 | ID  | Config | Config | Config | Config |   Oth  |
 |     |   A    |   B    |   C    |   D    |        |
 +-----+--------+--------+--------+--------+--------+
 | 0x0 |   2    |   0    |   0    |   4    |   3    |
 | 0x1 |   0    |   0    |   0    |   0    |   4    |
 | 0x2 |   0    |   1    |   0    |   1    |   5    |
 +-----+--------+--------+--------+--------+--------+

desired output :

 +-----+---+---+---+---+-----+
 | ID  |     Config    | Oth |
 +     +---+---+---+---+     |
 |     | A | B | C | D |     |
 +-----+---+---+---+---+-----+
 | 0x0 | 2 | 0 | 0 | 4 |  3  |
 | 0x1 | 0 | 0 | 0 | 0 |  4  |
 | 0x2 | 0 | 2 | 0 | 1 |  5  |
 +-----+---+---+---+---+-----+
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I'm not completely sure what you're going to use the table for, but I would perhaps suggest switching to the Pandas library. They have extensive support for all kinds of data labeling.

import pandas as pd

column_names = pd.DataFrame([["Config", "A"], 
                             ["Config", "B"], 
                             ["Config", "C"], 
                             ["Config", "D"], 
                             ["0th", ""]], 
                             columns=["ID", ""])

rows = [["2", "0", "0", "4", "3"],
        ["0", "0", "0", "0", "4"],
        ["0", "2", "0", "1", "5"]]

columns = pd.MultiIndex.from_frame(column_names)
index = ["0x0", "0x1", "0x2"]

df = pd.DataFrame(rows, columns=columns, index=index)
display(df)

enter image description here

over 4 years ago · Santiago Trujillo Denunciar
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda