0
0
Pandasdata~15 mins

Creating DataFrame from dictionary in Pandas - Try It Yourself

Choose your learning style9 modes available
Creating DataFrame from dictionary
📖 Scenario: You work in a small shop and keep track of your products and their prices. You want to organize this information in a table to see it clearly.
🎯 Goal: Create a pandas DataFrame from a dictionary that holds product names and their prices.
📋 What You'll Learn
Create a dictionary called products with exact keys and values
Create a pandas DataFrame called df from the products dictionary
Print the DataFrame df to see the organized table
💡 Why This Matters
🌍 Real World
Organizing product data in tables helps shop owners quickly see prices and manage inventory.
💼 Career
Data scientists often convert raw data like dictionaries into DataFrames for easy analysis and visualization.
Progress0 / 4 steps
1
Create the products dictionary
Create a dictionary called products with these exact entries: 'Apple': 0.5, 'Banana': 0.3, 'Orange': 0.7
Pandas
Need a hint?

Use curly braces {} to create a dictionary with keys as product names and values as prices.

2
Import pandas library
Import the pandas library using the alias pd
Pandas
Need a hint?

Use import pandas as pd to import the pandas library.

3
Create DataFrame from dictionary
Create a pandas DataFrame called df from the products dictionary. Use pd.DataFrame.from_dict(products, orient='index', columns=['Price']) to make product names the index and prices a column named 'Price'.
Pandas
Need a hint?

Use pd.DataFrame.from_dict() with orient='index' and columns=['Price'] to create the DataFrame.

4
Print the DataFrame
Print the DataFrame df to display the table of products and prices.
Pandas
Need a hint?

Use print(df) to show the DataFrame.