There are some light and useful python packages for this purpose:

1. tabulate

https://pypi.python.org/pypi/tabulate

from tabulate import tabulate
print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age']))
Name      Age
------  -----
Alice      24
Bob        19

tabulate has many options to specify headers and table format.

print(tabulate(
    [['Alice', 24], ['Bob', 19]],
    headers=['Name', 'Age'],
    tablefmt='orgtbl'))
| Name   |   Age |
|--------+-------|
| Alice  |    24 |
| Bob    |    19 |

2. PrettyTable

https://pypi.python.org/pypi/PrettyTable

from prettytable import PrettyTable
t = PrettyTable(['Name', 'Age'])
t.add_row(['Alice', 24])
t.add_row(['Bob', 19])
print(t)
+-------+-----+
|  Name | Age |
+-------+-----+
| Alice |  24 |
|  Bob  |  19 |
+-------+-----+

PrettyTable has options to read data from csv, html, sql database. Also you are able to select subset of data, sort table and change table styles.

3. texttable

https://pypi.python.org/pypi/texttable

from texttable import Texttable
t = Texttable()
t.add_rows([['Name', 'Age'], ['Alice', 24], ['Bob', 19]])
print(t.draw())
+-------+-----+
| Name  | Age |
+=======+=====+
| Alice | 24  |
+-------+-----+
| Bob   | 19  |
+-------+-----+

with texttable you can control horizontal/vertical align, border style and data types.

4. termtables

https://github.com/nschloe/termtables

import termtables as tt

string = tt.to_string(
    [["Alice", 24], ["Bob", 19]],
    header=["Name", "Age"],
    style=tt.styles.ascii_thin_double,
    # alignment="ll",
    # padding=(0, 1),
)
print(string)
+-------+-----+
| Name  | Age |
+=======+=====+
| Alice | 24  |
+-------+-----+
| Bob   | 19  |
+-------+-----+

with texttable you can control horizontal/vertical align, border style and data types.

Other options

  • terminaltables - Easily draw tables in terminal/console applications from a list of lists of strings. Supports multi-line rows.
  • asciitable can read and write a wide range of ASCII table formats via built-in Extension Reader Classes.
Answer from iman on Stack Overflow
Top answer
1 of 16
1042

There are some light and useful python packages for this purpose:

1. tabulate

https://pypi.python.org/pypi/tabulate

from tabulate import tabulate
print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age']))
Name      Age
------  -----
Alice      24
Bob        19

tabulate has many options to specify headers and table format.

print(tabulate(
    [['Alice', 24], ['Bob', 19]],
    headers=['Name', 'Age'],
    tablefmt='orgtbl'))
| Name   |   Age |
|--------+-------|
| Alice  |    24 |
| Bob    |    19 |

2. PrettyTable

https://pypi.python.org/pypi/PrettyTable

from prettytable import PrettyTable
t = PrettyTable(['Name', 'Age'])
t.add_row(['Alice', 24])
t.add_row(['Bob', 19])
print(t)
+-------+-----+
|  Name | Age |
+-------+-----+
| Alice |  24 |
|  Bob  |  19 |
+-------+-----+

PrettyTable has options to read data from csv, html, sql database. Also you are able to select subset of data, sort table and change table styles.

3. texttable

https://pypi.python.org/pypi/texttable

from texttable import Texttable
t = Texttable()
t.add_rows([['Name', 'Age'], ['Alice', 24], ['Bob', 19]])
print(t.draw())
+-------+-----+
| Name  | Age |
+=======+=====+
| Alice | 24  |
+-------+-----+
| Bob   | 19  |
+-------+-----+

with texttable you can control horizontal/vertical align, border style and data types.

4. termtables

https://github.com/nschloe/termtables

import termtables as tt

string = tt.to_string(
    [["Alice", 24], ["Bob", 19]],
    header=["Name", "Age"],
    style=tt.styles.ascii_thin_double,
    # alignment="ll",
    # padding=(0, 1),
)
print(string)
+-------+-----+
| Name  | Age |
+=======+=====+
| Alice | 24  |
+-------+-----+
| Bob   | 19  |
+-------+-----+

with texttable you can control horizontal/vertical align, border style and data types.

Other options

  • terminaltables - Easily draw tables in terminal/console applications from a list of lists of strings. Supports multi-line rows.
  • asciitable can read and write a wide range of ASCII table formats via built-in Extension Reader Classes.
2 of 16
325

Some ad-hoc code:

row_format ="{:>15}" * (len(teams_list) + 1)
print(row_format.format("", *teams_list))
for team, row in zip(teams_list, data):
    print(row_format.format(team, *row))

This relies on str.format() and the Format Specification Mini-Language.

🌐
LearnPython.com
learnpython.com › blog › print-table-in-python
How to Pretty-Print Tables in Python | LearnPython.com
For analytics reports or scientific publications, there are various latex formats as well as support for publishing tables in the popular project management software Jira or on GitHub. Here’s an example showing how you can use one line of Python to prepare tabular data to be published online using the html format: >>> print(tabulate(table, headers='firstrow', tablefmt='html')) <table> <thead> <tr><th style="text-align: right;"> col 1</th><th style="text-align: right;"> col 2</th><th style="text-align: right;"> col 3</th><th style="text-align: right;"> col 4</th></tr> </thead> <tbody> <tr><td
Discussions

Best tool for printing tables in Jupyter notebook?
Lets say I had something like: var | expected_value | actual_value -----|----------------|-------------- a | 5 | 5 s | 8 | 8 d | 13 | 14 f | 21 | 23 z | 34 | 35 What’s the best tool for printing the table in Jupyter so it looks nicer than just a pretty print? edit: could just look something ... More on discourse.julialang.org
🌐 discourse.julialang.org
12
0
May 6, 2017
How to print data in a table format?
Check out the rich library: https://rich.readthedocs.io/en/latest/tables.html More on reddit.com
🌐 r/learnpython
11
1
April 27, 2021
🌐
Reddit
reddit.com › r/learnpython › how do i print a table in python while keeping appopriate space between each element ?
r/learnpython on Reddit: How do I print a table in python while keeping appopriate space between each element ?
April 6, 2022 -

Hey, i'm a beginner in python and it's been only couple of weeks since i've been into the world of coding. What I want to do is to print a table, by a table I mean a list that contains sublists and I want them to be printed in a form of a table, when printing it using the following code :

for i in range(n+1):
    print(*lst[i],end='')
    print()

The printed table looks like :

1 2 89 92
4 56 84 144
1 5 0 6
6 63 173 242

My concern here is that I want it to be printed in a more organized way, so that it would like :

1  2   89   92
4  56  84   144
1  5   0    6
6  63  173  242

Any help will be appreciated ! Thanks in advance !

🌐
PyPI
pypi.org › project › tabulate
tabulate · PyPI
It corresponds to grid_tables in Pandoc Markdown extensions: >>> print(tabulate(table, headers, tablefmt="grid")) +--------+-------+ | item | qty | +========+=======+ | spam | 42 | +--------+-------+ | eggs | 451 | +--------+-------+ | bacon | 0 | +--------+-------+
🌐
GeeksforGeeks
geeksforgeeks.org › python › printing-lists-as-tabular-data-in-python
Printing Lists as Tabular Data in Python - GeeksforGeeks
July 23, 2025 - Explanation: Each sublist represents a row of data, while the list b provides the column headers 'Name' and 'Age'. The tabulate() function combines them and prints a well-structured, easy-to-read table output. PrettyTable is a Python library designed to print ASCII tables in a visually pleasing manner.
🌐
YouTube
youtube.com › watch
Print a formatted table using Python - YouTube
See http://studycoding.org for all tutorials by Shad Sluiter.
Published: September 7, 2017
Find elsewhere
🌐
Medium
medium.com › @qemhal.h › different-ways-to-display-a-table-in-python-d867aefb624a
Different Ways to Display a Table in Python | by Qemhal Haritskhayru | Medium
April 26, 2024 - Whether you’re working with a large datasets, the ability to present data clearly, or just simply an organized manner. In Python printing tabular data in a readable format is a common requirements across various domains, from data science to web development.
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.7 documentation
>>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142. Passing an integer after the ':' will cause that field to be a minimum number of characters wide. This is useful for making columns line up. >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678} >>> for name, phone in table.items(): ...
🌐
GitHub
gist.github.com › jhcepas › 5884168
nice table printing in python · GitHub
nice table printing in python. GitHub Gist: instantly share code, notes, and snippets.
🌐
Pandas
pandas.pydata.org › docs › user_guide › style.html
Table Visualization — pandas 3.0.6 documentation
To control the display value, the text is printed in each cell as a string, and we can use the .format() and .format_index() methods to manipulate this according to a format spec string or a callable that takes a single value and returns a string. It is possible to define this for the whole table, or index, or for individual columns, or MultiIndex levels.
🌐
Python
docs.python.org › 3 › library › pprint.html
pprint — Data pretty printer
Source code: Lib/pprint.py The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter. If the formatted struc...
🌐
LabEx
labex.io › tutorials › python-how-to-create-a-reusable-table-printing-function-for-diverse-data-structures-in-python-417941
How to create a reusable table printing function for diverse data structures in Python | LabEx
By using the print_table() function, you can easily display your data in a tabular format, regardless of the underlying data structure. This makes it a versatile and reusable tool for presenting information in your Python applications.
🌐
Python
docs.python.org › 3 › library › csv.html
csv — CSV File Reading and Writing
Eric Idle John Cleese >>> print(row) {'first_name': 'John', 'last_name': 'Cleese'}
🌐
Codecademy
codecademy.com › docs › markdown › tables
Markdown | Tables | Codecademy
May 15, 2024 - | Python Hat | True | 23.99 | | SQL Hat | True | 23.99 | | Codecademy Tee | False | 19.99 | | Codecademy Hoodie | False | 42.99 | Copy to clipboard · Copy to clipboard · :-- means the column is left aligned. --: means the column is right aligned. :-: means the column is center aligned. Text can be formatted within tables.
🌐
Sololearn
sololearn.com › en › Discuss › 2769082 › formatted-print-of-a-table-in-python
Formatted print of a table in python
sl_scroll_/de/Discuss/2689918/i-made-a-bmi-calculator-in-python-and-youa-are-supposed-to-write-the-height-in-meter-i-want-whenever-you-write-the-height-in-cePending
🌐
GitHub
gist.github.com › jerblack › 4daade57690dadcb6b1c330fc00295e3
Python table printing function which will print a structured table with headers, defined column widths, automatic text wrapping in columns, and automatic table sizing to fit the table within the terminal width. · GitHub
Python table printing function which will print a structured table with headers, defined column widths, automatic text wrapping in columns, and automatic table sizing to fit the table within the terminal width. - print_table.py
🌐
Readthedocs
tableprint.readthedocs.io
Tableprint — Tableprint 0.8.0 documentation
You can use it to print single rows of data at a time (useful for printing ongoing computation results). ... Tableprint offers two functions that print a table directly, tableprint.table and tableprint.dataframe. The first takes a numpy array and a list of headers, whereas the second takes a pandas DataFrame as input.
🌐
Julia Programming Language
discourse.julialang.org › general usage
Best tool for printing tables in Jupyter notebook? - General Usage - Julia Programming Language
May 6, 2017 - Lets say I had something like: var | expected_value | actual_value -----|----------------|-------------- a | 5 | 5 s | 8 | 8 d | 13 | 14 f | 21 | 23 z | 34 | 35 What’s the best tool for printing the table in Jupyter so it looks nicer than just a pretty print? edit: could just look something like datatables.js.
🌐
Reddit
reddit.com › r/learnpython › how to print data in a table format?
r/learnpython on Reddit: How to print data in a table format?
April 27, 2021 -

Hi Guys,

Please help me out, I am very weak in programming. I have the below code block which prints out all EC2 instances in an AWS account that are not of the latest generation along with the Cloudformation template used to provision them. The code is working fine now, it's just I need the output to be in a table. I tried using tabulate (commented out in the code block below) but the problem is it prints out and repeats the "headers" specified in each row instead of just on the very top, i think this is because of the whole thing is wrapped in for loop, not sure how I can work around it. I was told that the csv module maybe helpful but I looked python doc and it looks like that is for reading data from a .csv file and then processing it using the csv module. If you guyz can edit my code below and paste it here with the modification needed to display the data in a table format, I would be ever grateful to you. Please help me :( :( :(

import boto3
from tabulate import tabulate
 
ec2 = boto3.resource('ec2')
latestInstanceTypes = ['t3', 'm5', 'c5']

for instance in ec2.instances.all():
    if instance.instance_type.split('.')[0] not in latestInstanceTypes:
        stack_ids = [x['Value'] for x in instance.tags if x['Key'] == 'aws:cloudformation:stack-id']
        stack_id = stack_ids[0] if len(stack_ids) else None

        instance_names = [x['Value'] for x in instance.tags if x['Key'] == 'Name']
        instance_name = instance_names[0] if len(instance_names) else None
        #print(tabulate([[instance.id, instance.platform, instance.instance_type, instance.public_ip_address, instance.image.id, instance.state, stack_id]], headers=['Id', 'Platform', 'Type', 'Public IPv4', 'AMI', 'State', 'CF Template'], tablefmt='orgtbl'))
        print(
            "Id: {0}\nName: {1}\nType: {2}\nCFTemplate: {3}\nPlatform: {4}\nAMI: {5}\nState: {6}\n".format(
            instance.id, instance_name, instance.instance_type, stack_id, instance.platform, instance.image.id, instance.state
            )
        )