Printing Lists as Tabular Data in Python
In this post, I will explain to you how you can Print a List as Tabular Data in Python language.
Before going further let me explain to you about tabular data.
Tabular data is the data that is well maintained or the data which is in the form of rows and columns which contain some information.
Printing Python List in Tabular Form
Now to print list in Tabular Format we can do it using various method in Python. We have various Python packages to do it but here I’ll discuss with you most simplest and easy one using pandas library of Python.
Using pandas library in Python
pandas is a Python library that has various purpose or we can say it is an important library for data analysis and data manipulation.
To know more about pandas and to know how to install it refer to this link https://pandas.pydata.org/
Using pandas library we can easily change our list into a Tabular Data as below:-
#Python program to print list in Tabular Data #first import pandas library import pandas as pd l=['Apple','Banana','Mango','Grapes'] #we'll so our list l in the tabular data with column name fruits df=pd.DataFrame(l,columns=['Fruits']) print(df)
After running the above code we will see the result as given below:
Fruits 0 Apple 1 Banana 2 Mango 3 Grapes