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

631
Views
Python tabulate: tener múltiples encabezados con celdas combinadas

¿Hay alguna forma de especificar múltiples encabezados con celdas combinadas en python?

conjunto de datos de ejemplo:

 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"))

salida actual de tabular:

 +-----+--------+--------+--------+--------+--------+ | 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 | +-----+--------+--------+--------+--------+--------+

salida deseada :

 +-----+---+---+---+---+-----+ | 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 answers
Answer question

0

No estoy completamente seguro de para qué usará la tabla, pero tal vez sugeriría cambiar a la biblioteca de Pandas. Tienen un amplio soporte para todo tipo de etiquetado de datos.

 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)

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report
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!