Skip to content
Related Articles

Related Articles

Create pandas dataframe from lists using dictionary
  • Last Updated : 13 Dec, 2018

Creating pandas data-frame from lists using dictionary can be achieved in multiple ways.

Method #1: Using pandas.DataFrame

With this method in Pandas we can transform a dictionary of list to a dataframe.




# importing pandas as pd
import pandas as pd
  
# dictionary of lists
dict = {'name':["aparna", "pankaj", "sudhir", "Geeku"],
        'degree': ["MBA", "BCA", "M.Tech", "MBA"],
        'score':[90, 40, 80, 98]}
  
df = pd.DataFrame(dict)
  
df


Output:

 

Method #2: Using from_dict() function.






# importing pandas as pd
import pandas as pd
  
# dictionary of lists
dict = {'name':["aparna", "pankaj", "sudhir", "Geeku"],
        'degree': ["MBA", "BCA", "M.Tech", "MBA"],
        'score':[90, 40, 80, 98]}
  
df = pd.DataFrame.from_dict(dict)
  
df


Output:

With the use of this function, we get some flexibility in arranging our data, such as the orientation of data, data type and name of the columns can be entered as parameter in the function.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :