avatarUmberto Grando

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

784

Abstract

0fbcbd5e377cc12f331.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined"> </div> </div> </figure></iframe></div></div></figure><p id="9d3c">For this first example we have our data in a standard Python list. We initialize the table using the Table class from rich and then we add columns and rows to the object.</p><p id="4441">To show the table we create a Console object (which is used in every rich function) and we finally print the table.</p><h1 id="7aba">A pandas table</h1><figure id="4e56"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*EXd6IP3FCqTbvjX8dAN6FA.png"><figcaption></figcaption></figure> <figure id="7d3a"> <div> <div>

            <if

Options

rame class="gist-iframe" src="/gist/Inzaniak/6922d5f4d952ed82f6748aac80b95b64.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined"> </div> </div> </figure></iframe></div></div></figure><p id="b673">This time we are going to use a pandas dataframe as a source. Rich does not support natively pandas dataframe to create a table (there are custom modules that can fix that), but we can transform the dataframe to two lists (rows, columns) in a few steps.</p><p id="5ef9">And that’s it for today. We are going to explore more of this awesome library in the next weeks. In the meantime you can have a look a the code on my <a href="https://github.com/Inzaniak/pybistuff/blob/master/Rich/main.py">github repo</a>.</p></article></body>

Create Tables in your Terminal with Python

Hello World!

Lately I’ve been playing a lot with a Python library called Rich.

Rich is a Python library for rich text and beautiful formatting in the terminal. It is pretty easy to use and fast to integrate in your projects.

Let me show you a few examples:

A basic table

For this first example we have our data in a standard Python list. We initialize the table using the Table class from rich and then we add columns and rows to the object.

To show the table we create a Console object (which is used in every rich function) and we finally print the table.

A pandas table

This time we are going to use a pandas dataframe as a source. Rich does not support natively pandas dataframe to create a table (there are custom modules that can fix that), but we can transform the dataframe to two lists (rows, columns) in a few steps.

And that’s it for today. We are going to explore more of this awesome library in the next weeks. In the meantime you can have a look a the code on my github repo.

Python
Terminal
Python Programming
Software Development
Software Engineering
Recommended from ReadMedium