0
0
Pandasdata~15 mins

Inplace operations consideration in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Inplace Operations Consideration with pandas
📖 Scenario: You work as a data analyst. You have a small sales dataset with product names and prices. You want to update the prices by applying a discount. You will learn how to do this with and without inplace operations in pandas.
🎯 Goal: Build a pandas DataFrame with product prices, create a discount rate variable, apply the discount to prices using inplace and non-inplace methods, and print the updated DataFrame.
📋 What You'll Learn
Create a pandas DataFrame called df with columns Product and Price with exact values
Create a variable discount with the value 0.1 (10% discount)
Apply the discount to the Price column using inplace operation
Print the updated DataFrame df
💡 Why This Matters
🌍 Real World
In real life, data analysts often need to update data values directly in their datasets. Understanding inplace operations helps save memory and write cleaner code.
💼 Career
Knowing how to use inplace operations in pandas is useful for data cleaning and transformation tasks in data science and analytics jobs.
Progress0 / 4 steps
1
Create the sales DataFrame
Import pandas as pd and create a DataFrame called df with these exact rows: Product as ['Pen', 'Notebook', 'Eraser'] and Price as [1.5, 3.0, 0.5].
Pandas
Need a hint?

Use pd.DataFrame with a dictionary for columns.

2
Create the discount variable
Create a variable called discount and set it to 0.1 to represent a 10% discount.
Pandas
Need a hint?

Just assign 0.1 to discount.

3
Apply discount using inplace operation
Use the df['Price'].mul() method with 1 - discount and inplace=True to update the Price column directly.
Pandas
Need a hint?

Use the *= operator to update the column inplace.

4
Print the updated DataFrame
Print the DataFrame df to see the updated prices after the discount.
Pandas
Need a hint?

Use print(df) to show the DataFrame.