Convering dictionary into dataframe pandas python

Post Reply
programmer
Posts: 9
Joined: 27 Mar 2019

Convering dictionary into dataframe pandas python

Post by programmer » 27 Mar 2019

Hello, I am new to pandas and I have written a code to store different values in the form of key and values pairs. Please have a look at the below code.

Code: Select all

countries_details = {'name': ['India', 'South Africa', 'Australia'],
'population in crores': [133, 6, 33],
'Best Place to Visit': ['Taj Mahal','Boulders Beach','MANLY BEACH']}
print(countries_details)
I want to convert this dictionary into dataframe. Can you please guide me how to apporach for it.

User avatar
Aisangam
Site Admin
Posts: 27
Joined: 24 Mar 2019
Location: Delhi, India
Contact:

Re: Convering dictionary into dataframe pandas python

Post by Aisangam » 27 Mar 2019

As I could look into the code, you have made the dictionary which holds both key and value. Data frame will take these keys as the headers and values as the rows. I hope you will also visit http://www.aisangam.com/blog/quick-intr ... dataframe/ to get used to basics of python. Now coming back to the code. Let me write down your code again for you as down

Code: Select all

countries_details = {'name': ['India', 'South Africa', 'Australia'],
'population in crores': [133, 6, 33],
'Best Place to Visit': ['Taj Mahal','Boulders Beach','MANLY BEACH']}
countries_details is your dictionary and just pass follow the below code to convert it into dataframe

Code: Select all

import pandas as pd
df = pd.DataFrame(countries_details)
print("Dataframe from dictionary is",df)
If you face any problem in importing pandas, you can install it using the below command

Code: Select all

pip install pandas

jaykumarjain
Posts: 1
Joined: 04 Jul 2019

Re: Convering dictionary into dataframe pandas python

Post by jaykumarjain » 04 Jul 2019

In the era of computers and its programming languages, Python is a programming language and also it is a high-level programming language it was created to provide ease to the programmers. It helps programmers to write clear, logical code for small and large-scale projects. Users and admirers of Python, especially those considered knowledgeable or experienced, are often referred to as Pythonists, Pythonistas, and Pythoneers. So if you want to have these tags before your name then join Universal Informatics to have its training. Universal Informatics is one of the best Python Training Institute in Indore. Visit once to know about more courses.

Post Reply