Python Pandas: Create a DataFrame using dict of dict

Profile picture for user devanshi.srivastava
Submitted by devanshi.srivastava on

We firstly create list and them convert them into dictionary, by using enumerate() function.


import pandas as pd

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

dict_names={k:v for k,v in enumerate(names)} #dictionary
dict_ages={k:v for k,v in enumerate(ages)}
dict_fees={k:v for k,v in enumerate(fees)}

students=pd.DataFrame({'Name':dict_names ,
                       'Fees Submitted':dict_fees})#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