0
0
Data Analysis Pythondata~15 mins

Adding and removing columns in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Adding and removing columns
📖 Scenario: You work in a small grocery store. You have a table of products with their prices and quantities. You want to add a new column for the total value of each product (price times quantity). Later, you decide to remove the quantity column to keep the table simple.
🎯 Goal: Create a data table using a dictionary, add a new column for total value, then remove the quantity column, and finally display the updated table.
📋 What You'll Learn
Create a dictionary called products with keys 'Name', 'Price', and 'Quantity' and the exact values specified.
Create a new column 'TotalValue' by multiplying Price and Quantity for each product.
Remove the 'Quantity' column from the dictionary.
Print the final products dictionary.
💡 Why This Matters
🌍 Real World
Stores and businesses often keep product data in tables. Adding and removing columns helps update the data as needed.
💼 Career
Data analysts and scientists frequently manipulate tables by adding calculated columns and cleaning data by removing unnecessary columns.
Progress0 / 4 steps
1
Create the initial products dictionary
Create a dictionary called products with these exact keys and values: 'Name' with the list ['Apple', 'Banana', 'Carrot'], 'Price' with the list [0.5, 0.3, 0.2], and 'Quantity' with the list [10, 20, 15].
Data Analysis Python
Need a hint?

Use a dictionary with keys 'Name', 'Price', and 'Quantity'. Each key should have a list of values.

2
Add a new column for total value
Create a new key 'TotalValue' in the products dictionary. Set its value to a list where each element is the product of the corresponding Price and Quantity values.
Data Analysis Python
Need a hint?

Use a list comprehension with zip(products['Price'], products['Quantity']) to multiply each pair.

3
Remove the Quantity column
Remove the 'Quantity' key and its values from the products dictionary using the del statement.
Data Analysis Python
Need a hint?

Use del products['Quantity'] to remove the column.

4
Print the final products dictionary
Print the products dictionary to display the updated table with the 'Name', 'Price', and 'TotalValue' columns.
Data Analysis Python
Need a hint?

Use print(products) to show the final dictionary.