Python Pandas: Create DataFrame using the zip() function

In this method we define the listened then zip them after that unzip them and then create dataframe.


import pandas as pd

names = ["John","Jill","Monica","Joey","Alice"] #create a list
ages = [22,24,20,24,26] #create another list
fees = [True,False,True,True,False]

list(zip(names,ages,fees)) #zipped list
unzip_file = [{'names':names,'ages':ages,'fees':fees}for names,ages,fees in zip(names,ages,fees)] #unzip the list
students = pd.DataFrame(unzip_file) #create the pandas dataframe

print(students) #print DataFrame


     name  age  Fees Submitted
0    John   22            True
1    Jill   24           False
2  Monica   20            True
3    Joey   24            True
4   Alice   26           False
Fri, 10/29/2021 - 19:37

Authored by

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.