Filter Data with Multiple Conditions Using & and | in pandas
📖 Scenario: You work in a small online store. You have a list of products with their prices and stock counts. You want to find products that meet certain conditions to decide what to promote or reorder.
🎯 Goal: Build a pandas DataFrame with product data, set a price threshold, filter products using multiple conditions combined with & (and) and | (or), and display the filtered results.
📋 What You'll Learn
Create a pandas DataFrame named
products with columns Product, Price, and Stock using the exact data provided.Create a variable
price_limit with the exact value 20.Use multiple conditions combined with
& and | to filter products where Price is less than price_limit and Stock is greater than 10, or where Product is exactly 'Notebook'.Store the filtered DataFrame in a variable named
filtered_products.Print the
filtered_products DataFrame.💡 Why This Matters
🌍 Real World
Filtering data with multiple conditions is common in business to find products that meet specific criteria, like affordable price and enough stock.
💼 Career
Data analysts and scientists often filter datasets using multiple conditions to prepare data for reports, dashboards, or decision-making.
Progress0 / 4 steps