0
0
Pandasdata~30 mins

Feature engineering basics in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Feature engineering basics
📖 Scenario: You work as a data analyst for a retail company. You have sales data with product prices and quantities sold. You want to create new features to better understand the total sales value for each product.
🎯 Goal: Create a new feature called total_sales by multiplying price and quantity for each product in the sales data.
📋 What You'll Learn
Use pandas to create and manipulate data.
Create a DataFrame with product sales data.
Add a new column total_sales by multiplying price and quantity.
Print the updated DataFrame to see the new feature.
💡 Why This Matters
🌍 Real World
Feature engineering helps improve data quality and model performance by creating meaningful new columns from existing data.
💼 Career
Data scientists and analysts often create new features to help machine learning models understand data better and make better predictions.
Progress0 / 4 steps
1
Create the sales data DataFrame
Create a pandas DataFrame called sales_data with these exact columns and values: product with ['A', 'B', 'C'], price with [10, 20, 15], and quantity with [5, 3, 8].
Pandas
Need a hint?

Use pd.DataFrame with a dictionary containing the columns and their values.

2
Set up a variable for the new feature name
Create a variable called new_feature and set it to the string 'total_sales'.
Pandas
Need a hint?

Just assign the string 'total_sales' to the variable new_feature.

3
Create the new feature by multiplying price and quantity
Add a new column to sales_data with the name stored in new_feature. Set this column to the product of the price and quantity columns.
Pandas
Need a hint?

Use sales_data[new_feature] to create the new column and multiply the two existing columns.

4
Print the updated DataFrame
Print the sales_data DataFrame to display the new total_sales feature.
Pandas
Need a hint?

Use print(sales_data) to show the DataFrame with the new column.