Skip to content

Instantly share code, notes, and snippets.

@ArthurDelannoyazerty
Created February 5, 2025 17:07
Show Gist options
  • Save ArthurDelannoyazerty/c2dfc597382824dbc5a62562b0725491 to your computer and use it in GitHub Desktop.
Save ArthurDelannoyazerty/c2dfc597382824dbc5a62562b0725491 to your computer and use it in GitHub Desktop.
Minimal code examples for tabulate

List to table

We transpose the list so that the Nth column is the Nth list of the entire array Column n = l[n-1])

headers = ['Column 1', 'Column 2', 'Column 3']
l = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]

table = tabulate.tabulate(list(map(list, zip(*l))), headers=headers, tablefmt="github")

Dict to table

d = {'Column 1': [1, 2, 3],
     'Column 2': [4, 5, 6],
     'Column 3': [7, 8, 9],}

table = tabulate.tabulate(d, headers=list(d.keys()), tablefmt="github")

Result

|   Column 1 |   Column 2 |   Column 3 |
|------------|------------|------------|
|          1 |          4 |          7 |
|          2 |          5 |          8 |
|          3 |          6 |          9 |

Tabulate formats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment