Professional Tables in Python

NeuralNine · Beginner ·💻 AI-Assisted Coding ·4y ago

Key Takeaways

The video demonstrates how to print professional tables in Python, likely using libraries such as tabulate or prettytable.

Full Transcript

[Music] what's going on guys welcome back in today's what i'm going to show you how to display beautiful tables in the command line using python and for that we're going to use a module called tabulate so we're going to start by opening up a command line of our choice and we're going to type on windows pip install tabulate or on linux and i think also on mac pip 3 install tabulate and this is going to install the respective module and now all we need to do is we need to import it by saying from tabulate import tabulate and this can be quite useful for those of you who are into data science and work with data sets on a regular basis because this tool allows us to just display data in a table format easily without worrying too much about formatting ourself so let's start with a very simple example let's say we have some table data here and i'm going to use the copilot if it is available to generate some data um it is enabled so let's see if we can do that we're going to start with a very simple thing like name age job is a good suggestion and then we're going to just fill up with some data so for example mike 22 programmer um john 24 teacher uh jane 23 designer jack 25 manager and let's add one more jill 26 programmer so this is an ordinary python list so we have um actually two dimensional lists so we have list inside a list but essentially this is just a basic python list so if we go ahead and print this table data without tabulating so just table data we're going to see that this does not look first of all like a table and even if we do something like four row in table data for column in table data or column in row actually print column and we end without a line break and then every row we make a line break that works but it's still not really beautiful now in this case uh it actually works because the names are all four characters long but if i now change jill to some long name like that you're going to see that the whole table structure is now skewed um and i can try even to do something like okay don't use spaces use tabs for example or something like that or use multiple tabs but at the end of the day it's always different and you need to to consider these things here so it makes more sense to use a module like tabulate to do that and it actually works quite uh simple you just type print and then tabulate now let's turn off the github copilot because otherwise we're going to get suggestions all the time tabulate um and we're going to tabulate the table data and we're going to say the headers so the headers of the table is going to be the first row of um of the table data so this will be taken as the headers we can of course alternatively instead of passing the string also pass a list of um of columns but in this case uh this works and now you can see we have a very basic table here uh that is structured well so we have the necessary uh space here and now we can do is we can also add a table format and we have a lot of different table formats to choose from i recommend if you want to see all of them you go to documentation they have a very um nice section on the different formats here i'm going to show you a couple of them um table format for example we can go with p sql which i think is for postgres sql um and you can see that now it looks like that or we can choose something like uh plane and i think plane removes all all the separators so like that or the one that i uh enjoy probably the most is what was it fancy underscore grit there you go so this actually looks like uh pseudographic so this looks like it is actually a graphic or something but this can be used now quite easily we have also something like html this of course won't print something visual into the command line it's going to give us the html code but what we can do is we can go ahead and say with open and then my table dot html in writing mode s f f dot write tabulate tabulate uh table data and the table format is going to be html now we can run this now we have this html file and i think we should be able to open it in the browser from here so firefox and take some time to load here but there you go you have an html file with the table same can be done uh for la la tech i think this is how it's pronounced uh by the way so essentially we're going to change this to tex and then we have this here simple table so this can be used with ordinary python list but we can also use that with numpy arrays and with pandas data frames but we can also use that with a dictionary so let's start with the dictionaries first let's change all this into a dictionary actually i think we can turn on the autocompletion for that uh let's go with data and then this here and then we can say okay name and mike john jane jackson long name h there you go and then um jump there you go so that's the dictionary we can delete that now and what we can do here is we can say not right but print again and we essentially say okay the data is what we want to print here would want to use here and the headers this time is not going to be first row because we don't have a list we're going to say keys because we want to have the keys off of the dictionary those are going to be the column names and the format is going to be for example again fancy grid there you go works as well and also one option we can add here is show the index uh now we don't have an index right now but we can say show index equals true or actually i think i'm not sure if true is going to work let's see uh actually it works but we can also pass always which is the way that is described in um in the documentation but you can see now we have these indices here all right so let's see that we can also do that in numpy so we can say import numpy as np and import pandas spd for later on um and essentially we can basically just go ahead and say um for numpy let's let's just go with a sampler right here i'm going to call this array equals np array and now we're going to have some sample data one two three um let's do one two three and then four five six and then 789 and then all we want to do is we want to say okay print the array and the headers we can now specify uh a separate list of column names and we're going to just call this call 1 call 2 call 3 and they go that's it essentially and instead of passing this string here we're going to say columns and there you go okay we have a problem what's the problem here oh this of course needs to be in the list itself there you go with the indices now we have the numpy array displayed as a table and last but not least the pandas data frame so let's just keep uh the data that we have here and we're going to say df equals pd data frame of the data so from the dictionary we're going to create uh a pandas data frame and we can now go ahead comment this out and just print the ordinary data frame because the data frame itself already has a way of being printed as a table so you can see that we already have a table like structure but we can still go ahead and print the table or the data frame um using a different format so for example the fancy grid looks better than this in my opinion and here for the columns we just pass or for the headers we pass just keys again and there you go so this is the data frame now displayed in a fancy grid style so that's it for today's udoption joining up you learned something if so let me know by hitting the like button leaving a comment in the comment section down below and of course don't forget to subscribe and hit the notification bell to not miss a single future video for free other than that thank you much for watching see you next video and bye [Music] you

Original Description

Today we learn how to print professional tables in Python. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm 🎵 Outro Music From: https://www.bensound.com/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to print professional tables in Python, which is useful for data analysis and presentation. The video likely covers the basics of table formatting and how to use Python libraries to achieve professional-looking tables. By watching this video, viewers can learn how to improve their coding skills and make their data more presentable.

Key Takeaways
  1. Import necessary libraries
  2. Define table data
  3. Use library functions to format table
  4. Print formatted table
💡 Using Python libraries such as tabulate or prettytable can greatly improve the presentation of table data.

Related Reads

📰
Cursor Pricing 2026: Free vs Pro vs Ultra — Which Plan?
Learn how to choose the right Cursor plan for your coding needs and budget, and discover how this Agentic AI coding tool can boost your productivity
Dev.to AI
📰
enable Consistent AI Coding with Persistent Context Layers
Learn how persistent context layers can improve AI coding consistency and reliability
Dev.to AI
📰
LeetCode Isn’t Dead. Your Interview Prep Strategy Is.
Update your interview prep strategy to focus on practical skills and real-world problem-solving, as LeetCode-style interviews are evolving
Medium · Programming
📰
Build a UGC video moderation pipeline with FFmpeg + NudeNet
Learn to build a UGC video moderation pipeline using FFmpeg and NudeNet to ensure safe and respectful user-generated content
Dev.to · Mason K
Up next
Copilot Cowork: Setup, Skills, Plugins & Pricing
Matt Tutorials
Watch →