0
0
Pandasdata~30 mins

Why DataFrame creation matters in Pandas - See It in Action

Choose your learning style9 modes available
Why DataFrame creation matters
📖 Scenario: Imagine you work in a small store. You want to keep track of daily sales data like product names, quantities sold, and prices. Organizing this data well helps you understand your business better.
🎯 Goal: You will create a pandas DataFrame from scratch with sales data. Then, you will set a threshold to filter products sold in large quantities. Finally, you will display the filtered data to see which products sold the most.
📋 What You'll Learn
Create a pandas DataFrame with exact sales data
Create a variable for quantity threshold
Filter the DataFrame for products with quantity sold above the threshold
Print the filtered DataFrame
💡 Why This Matters
🌍 Real World
Organizing sales data in a DataFrame helps store owners quickly analyze which products sell well and make better decisions.
💼 Career
Data scientists and analysts often create and filter DataFrames to prepare data for reports and insights.
Progress0 / 4 steps
1
Create the sales DataFrame
Import pandas as pd. Create a DataFrame called sales_data with these exact columns and values: 'Product': ['Apples', 'Bananas', 'Cherries', 'Dates'], 'Quantity': [10, 25, 7, 30], 'Price': [0.5, 0.3, 0.2, 1.0].
Pandas
Need a hint?

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

2
Set the quantity threshold
Create a variable called quantity_threshold and set it to 15. This will help us find products sold in quantities greater than 15.
Pandas
Need a hint?

Just create a variable and assign the number 15 to it.

3
Filter products by quantity
Create a new DataFrame called high_sales by filtering sales_data to include only rows where Quantity is greater than quantity_threshold.
Pandas
Need a hint?

Use boolean indexing with sales_data['Quantity'] > quantity_threshold inside the square brackets.

4
Display the filtered DataFrame
Print the high_sales DataFrame to see the products sold in quantities greater than 15.
Pandas
Need a hint?

Use print(high_sales) to show the filtered data.