close

How to print Data in Tabular Format in Python

Hi guys. How are you all? I hope you all fine. Today in this tutorial we will learn about How to print Data in Tabular Format in Python. we can store our data in the list and we can print it. But if we want to print it in rows and columns then this tutorial will help you. Here we will learn to print data in tabular format. So lets learn this by given methods:

How to print Data in Tabular Format in Python

  1. Print Data in Tabular Format in Python

    to print Data in Tabular Format in Python just Use pandas.dataframe(). You can use pandas.dataframe() for to print Data in Tabular Format in Python. Here we will import pandas and then use my list and pd.dataframe() and print it. It will give the all data in tabular form. S lets learn this by given below example: import pandas as pd mydict = [ ["Jeny", 12, 95], ["Meet", 11, 98], ["Raj", 12, 80]] df = pd.DataFrame(mydict, columns = ['Name','Standard','Percent']) print(df) Output : Name Standard Percent 0 Jeny 12 95 1 Meet 11 98 2 Raj 12 80

  2. How to print Data in Tabular Format in Python

    to print Data in Tabular Format in Python just Use format(). By using format() you can print your data in a tabular format in python. First of all make a list you want to convert into tabular form. Then print your header for the table. And after it use for loop and use the format() function. It will print your list into tabular form. So lets learn about of this by given below example. I hope this will help you. mydict = [ ["Jeny", 12, 95], ["Meet", 11, 98], ["Raj", 12, 80]] print ("{:<8} {:<15} {:<10}".format('Name','Standard','Percent')) for v in mydict: name, std, perc = v print ("{:<8} {:<15} {:<10}".format( name, std, perc)) Output : Name Standard Percent Jeny 12 95 Meet 11 98 Raj 12 80

Method 1: Use pandas.dataframe()

You can use pandas.dataframe() for to print Data in Tabular Format in Python. Here we will import pandas and then use my list and pd.dataframe() and print it. It will give the all data in tabular form. S lets learn this by given below example:

import pandas as pd
mydict = [ ["Jeny", 12, 95],
     ["Meet", 11, 98],
     ["Raj", 12, 80]]
df = pd.DataFrame(mydict, columns = ['Name','Standard','Percent'])
print(df)

Output :

   Name  Standard  Percent
0  Jeny        12       95
1  Meet        11       98
2   Raj        12       80

Method 2: Use format()

By using format() you can print your data in a tabular format in python. First of all make a list you want to convert into tabular form. Then print your header for the table. And after it use for loop and use the format() function. It will print your list into tabular form. So lets learn about of this by given below example. I hope this will help you.

mydict = [ ["Jeny", 12, 95],
     ["Meet", 11, 98],
     ["Raj", 12, 80]]
print ("{:<8} {:<15} {:<10}".format('Name','Standard','Percent'))
for v in mydict:
    name, std, perc = v
    print ("{:<8} {:<15} {:<10}".format( name, std, perc))

Output :

Name     Standard        Percent   
Jeny     12              95
Meet     11              98
Raj      12              80

Method 3: Use tabulate

By using tabulate you can print a data into tabular form. So here this method will teach you to print it. First of all you have to import tabulate after of it make your list you want to convert into tabulate form the use the tabulate() function and print your headers. You can find out the tabulate form of the list in my output. So lets learn this without wasting your time.

from tabulate import tabulate
mydict = [ ["Jeny", 12, 95],
     ["Meet", 11, 98],
     ["Raj", 12, 80]]
print(tabulate(mydict, headers=["Name", "Standard", "Percent"]))

Output :

Name      Standard    Percent
------  ----------  ---------
Jeny            12         95
Meet            11         98
Raj             12         80

Conclusion

Hope all 6 Method Are Useful For You. Comment Below Which Method You Used To Convert String To Datetime In Python. Thank You.

Also Read

Leave a Comment