0
0
Pandasdata~15 mins

applymap() for DataFrame-wide operations in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Using applymap() for DataFrame-wide Operations
📖 Scenario: You work in a small grocery store. You have a table showing the prices of different fruits in different stores. You want to increase all prices by 10% to prepare for a sale.
🎯 Goal: You will create a table of fruit prices, set a price increase rate, use applymap() to increase all prices, and then show the new prices.
📋 What You'll Learn
Create a pandas DataFrame called prices with exact fruit prices for three stores.
Create a variable called increase_rate with the value 1.10.
Use applymap() with a lambda function to multiply each price by increase_rate and save it as new_prices.
Print the new_prices DataFrame.
💡 Why This Matters
🌍 Real World
Stores often need to update prices for all products quickly. Using applymap() helps apply changes to every price in a table easily.
💼 Career
Data analysts and scientists use pandas and applymap() to clean and transform data tables efficiently.
Progress0 / 4 steps
1
Create the fruit prices DataFrame
Create a pandas DataFrame called prices with these exact values: columns are 'Store A', 'Store B', 'Store C'; index is 'Apple', 'Banana', 'Cherry'. The prices are:
Store A: 1.00, 0.50, 3.00
Store B: 1.20, 0.45, 2.80
Store C: 0.95, 0.55, 3.10
Pandas
Need a hint?

Use pd.DataFrame with a dictionary for columns and a list for the index.

2
Set the price increase rate
Create a variable called increase_rate and set it to 1.10 to represent a 10% price increase.
Pandas
Need a hint?

Just assign the number 1.10 to the variable increase_rate.

3
Use applymap() to increase all prices
Use applymap() on the prices DataFrame with a lambda function that multiplies each price by increase_rate. Save the result in a new DataFrame called new_prices.
Pandas
Need a hint?

Use prices.applymap(lambda price: price * increase_rate) to create new_prices.

4
Print the new prices DataFrame
Print the new_prices DataFrame to see the updated prices after the 10% increase.
Pandas
Need a hint?

Use print(new_prices) to show the updated prices.