0
0
Pandasdata~30 mins

Arithmetic operations on columns in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Arithmetic operations on columns
📖 Scenario: You work in a small store and keep track of product prices and quantities sold in a table. You want to calculate the total sales amount for each product.
🎯 Goal: Create a pandas DataFrame with product data, set a tax rate, calculate total sales including tax for each product, and display the results.
📋 What You'll Learn
Create a pandas DataFrame with product names, prices, and quantities
Create a variable for the tax rate
Calculate total sales including tax for each product using arithmetic operations on columns
Print the resulting DataFrame with the new total sales column
💡 Why This Matters
🌍 Real World
Stores and businesses often calculate total sales including taxes to understand revenue.
💼 Career
Data analysts and data scientists use pandas to manipulate sales data and perform calculations for reports.
Progress0 / 4 steps
1
Create the product DataFrame
Import pandas as pd and create a DataFrame called products with these exact columns and values: 'Product' with ['Pen', 'Notebook', 'Eraser'], 'Price' with [1.5, 3.0, 0.5], and 'Quantity' with [10, 5, 20].
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of column values.

2
Set the tax rate
Create a variable called tax_rate and set it to 0.1 to represent 10% tax.
Pandas
Need a hint?

Just assign 0.1 to the variable tax_rate.

3
Calculate total sales including tax
Create a new column in products called Total_Sales that calculates the total sales amount including tax for each product. Use the formula: Price * Quantity * (1 + tax_rate).
Pandas
Need a hint?

Use arithmetic operations on the DataFrame columns and assign the result to a new column.

4
Display the updated DataFrame
Print the products DataFrame to display the product details along with the new Total_Sales column.
Pandas
Need a hint?

Use print(products) to show the DataFrame.