Create pandas dataframe from lists using dictionary
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.
Recommended Posts:
- Create pandas dataframe from lists using zip
- Create a Pandas DataFrame from Lists
- Python | Create a Pandas Dataframe from a dict of equal length lists
- Python | Ways to create a dictionary of Lists
- Different ways to create Pandas Dataframe
- Using dictionary to remap values in Pandas DataFrame columns
- Create a column using for loop in Pandas Dataframe
- Create a Pandas DataFrame from List of Dicts
- Create a list from rows in Pandas DataFrame | Set 2
- Create a list from rows in Pandas dataframe
- Python | Convert list of nested dictionary into Pandas dataframe
- Create a new column in Pandas DataFrame based on the existing columns
- Creating Pandas dataframe using list of lists
- Python | Pandas DataFrame.fillna() to replace Null values in dataframe
- Python program to create a dictionary from a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



