Character Alignment

Asked

Viewed 646 times

1

alinhados

I wish someone could tell me how do I get the numbers to line up that way with the words in the top index, I’m making a replica of that example for a college job, but I can’t get the numbers to line up without ever expanding off the screen. I’m using Pyhton 3.4.

Thank you if you can help me

1 answer

1


You can use the library tabulate and go adapting your need, see an example of use based on some data you presented:

>>> from tabulate import tabulate
>>> data = [[2000, 0.00, 0.01, 0.00, 0.00, 1485, 2128, 79, 286], [4000, 0.01, 0.02, 0.00, 0.00, 2286, 4673, 264, 92]]
>>> headers = ['n', 'Insercao', 'Selecao', 'Merge', 'Quick', 'Insercao', 'Selecao', 'Merge', 'Quick']
>>> print(tabulate(data, headers, tablefmt='psql'))
+------+------------+-----------+---------+---------+------------+-----------+---------+---------+
|    n |   Insercao |   Selecao |   Merge |   Quick |   Insercao |   Selecao |   Merge |   Quick |
|------+------------+-----------+---------+---------+------------+-----------+---------+---------|
| 2000 |       0    |      0.01 |       0 |       0 |       1485 |      2128 |      79 |     286 |
| 4000 |       0.01 |      0.02 |       0 |       0 |       2286 |      4673 |     264 |      92 |
+------+------------+-----------+---------+---------+------------+-----------+---------+---------+

Browser other questions tagged

You are not signed in. Login or sign up in order to post.