0
0
Data Analysis Pythondata~15 mins

map() for element-wise mapping in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using map() for Element-wise Mapping in Data Science
📖 Scenario: You work in a small grocery store. You have a list of prices for some fruits. You want to apply a discount to each price to prepare for a sale.
🎯 Goal: Learn how to use the map() function to apply a discount to each price in a list.
📋 What You'll Learn
Create a list of fruit prices
Create a discount rate variable
Use map() with a function to apply the discount to each price
Print the discounted prices as a list
💡 Why This Matters
🌍 Real World
Applying discounts or taxes to prices is common in retail and e-commerce. Using <code>map()</code> helps automate this process efficiently.
💼 Career
Data analysts and scientists often need to transform data element-wise. Knowing how to use <code>map()</code> is a basic but important skill.
Progress0 / 4 steps
1
Create a list of fruit prices
Create a list called prices with these exact values: 2.5, 3.0, 4.5, 1.2, 5.0.
Data Analysis Python
Hint

Use square brackets [] to create a list and separate values with commas.

2
Create a discount rate variable
Create a variable called discount_rate and set it to 0.1 to represent a 10% discount.
Data Analysis Python
Hint

Assign the value 0.1 to the variable discount_rate.

3
Use map() to apply the discount to each price
Use map() with a lambda function to create a new list called discounted_prices. The lambda function should subtract the discount from each price using price * discount_rate.
Data Analysis Python
Hint

Use map() with a lambda that takes price and returns price - price * discount_rate. Wrap the result with list().

4
Print the discounted prices
Print the list discounted_prices to see the prices after the discount.
Data Analysis Python
Hint

Use print(discounted_prices) to display the final list.