Skip to content
Related Articles

Related Articles

Create pandas dataframe from lists using dictionary

Improve Article
Save Article
Like Article
  • 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.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!