Skip to main content

Python Pandas: Create a DataFrame using dict of series

In this method first we need to create list and then make them series and finally create a dataframe.

Example

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]

series_names=pd.Series(names)#create series
series_ages=pd.Series(ages)
series_fees=pd.Series(fees)

students=pd.DataFrame({'Name':series_names ,
                       'Age':series_ages,
                       'Fees Submitted':series_fees})#create the pandas dataframe

print(students)#print dataframe

Output

     name  age  Fees Submitted
0    John   22            True
1    Jill   24           False
2  Monica   20            True
3    Joey   24            True
4   Alice   26           False
Submitted by devanshi.srivastava on October 29, 2021

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

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.