Wednesday, May 6, 2026
HomeLanguagesHow to convert Dictionary to Pandas Dataframe?

How to convert Dictionary to Pandas Dataframe?

Let’s discuss how to convert Python Dictionary to Pandas Dataframe. We can convert a dictionary to a pandas dataframe by using the pd.DataFrame.from_dict() class-method.

Example 1: Passing the key value as a list.




import pandas as pd
  
  
data = {'name': ['nick', 'david', 'joe', 'ross'],
        'age': ['5', '10', '7', '6']} 
new = pd.DataFrame.from_dict(data)
  
new


Output:

pandas-dataframe-from-dict-1

Example 2




import pandas as pd
  
  
data = [{'area': 'new-hills', 'rainfall': 100, 'temperature': 20},
         {'area': 'cape-town''rainfall': 70, 'temperature': 25},
         {'area': 'mumbai''rainfall': 200'temperature': 39 }]
  
df = pd.DataFrame.from_dict(data)
  
df


Output:

pandas-dataframe-from-dict-2

Example 3: Using the orient parameter to change the orientation of the dataframe from column to index




import pandas as pd
  
data ={'area': ['new-hills', 'cape-town', 'mumbai'],
       'rainfall':[100, 70, 200],
       'temperature':[20, 25, 39]}
  
df = pd.DataFrame.from_dict(data, orient ='index'
df
print(df)


Output:

pandas-dataframe-from-dict-3

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6889 POSTS0 COMMENTS
Nicole Veronica
12011 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12105 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6962 POSTS0 COMMENTS