. Advertisement .
..3..
. Advertisement .
..4..
Computers are mostly used to store information and extract information from it. Python is one of the most powerful programming languages. We can use Python to get computers to do most of the routine processes. This blog is all about how we can use Python to print data in Tabular Format.
How Can You Print Data in Tabular Format in Python?
Utilize formate to print data in tabular format in Python. In Python, you may print data in tabular format utilizing formate. It is extremely simple to utilize. Let’s take a look at an example of this:
dict = [ ["july", 15, 95], ["mitva", 12, 98], ["karan", 15, 92]] print ("{:<10} {:<10} {:<10}".format('Name','Age','Percent')) for v in dict: name, age, perc = v print ("{:<10} {:<10} {:<10}".format( name, age, perc))
Result:
Name Age Percent july 15 95 mitva 12 98 karan 15 92
from pytube import YouTube
Utilize pandas.dataframe() to print data in tabular format in Python. In Python, you can print data in tabular format utilizing pandas.dataframe(). It is extremely simple to utilize. Let’s take a look at an example of this:
[“july”, 15, 95], [“mitva”, 12, 98], [“karan”, 15, 92]] df = pd.DataFrame(dict, columns = [‘Name’,’Age’,’Percent’]) print(df)
Result:
Name Age Percent july 15 95 mitva 12 98 karan 15 92
Approach 1: Utilize formate
In Python, you may print data in tabular format utilizing formate. It is extremely simple to utilize. Let’s take a look at an example of this:
dict = [ ["july", 15, 95], ["mitva", 12, 98], ["karan", 15, 92]] print ("{:<10} {:<10} {:<10}".format('Name','Age','Percent')) for v in dict: name, age, perc = v print ("{:<10} {:<10} {:<10}".format( name, age, perc))
Result:
Name Age Percent
july 15 95
mitva 12 98
karan 15 92
Approach 2: Utilize pandas.dataframe()
In Python, you can print data in tabular format utilizing pandas.dataframe(). It is extremely simple to utilize. Let’s take a look at an example of this:
import pandas as pd dict = [ ["july", 15, 95], ["mitva", 12, 98], ["karan", 15, 92]] df = pd.DataFrame(dict, columns = ['Name','Age','Percent']) print(df)
Result:
Name Age Percent
july 15 95
mitva 12 98
karan 15 92
Conclusion
Printing Data in Tabular Format in Python is a confusing problem. We hope this blog has helped clear the air around how to do it. If you have more questions about this topic, please leave a comment below. Thank you for reading; we are always excited when one of our posts can provide useful information on a topic like this!
Leave a comment