import pandas as pd orders = pd.DataFrame( { "order_id": [1001, 1002, 1003, 1004, 1005, 1006], "customer": ["Ada", "Lin", "Maya", "Omar", "Nia", "Kai"], "region": ["EMEA", "APAC", "AMER", "EMEA", "APAC", "AMER"], "category": ["hardware", "software", "hardware", "service", "software", "hardware"], "qty": [3, 12, 7, 2, 15, 9], "total_usd": [150.0, 240.0, 875.0, 95.0, 360.0, 420.0], "status": ["paid", "paid", "open", "paid", "open", "paid"], } ) print(f"pandas {pd.__version__}") print() print("BASE") print(orders.to_string(index=False)) print() high_value = orders.loc[ orders["total_usd"] >= 300, ["order_id", "customer", "region", "total_usd"], ] print("FILTER_TOTAL") print(high_value.to_string(index=False)) print() regions = ["EMEA", "APAC"] priority_mask = (orders["region"].isin(regions)) & (orders["qty"] >= 10) priority = orders.loc[ priority_mask, ["order_id", "customer", "region", "qty", "total_usd"], ] print("FILTER_REGION_QTY") print(priority.to_string(index=False)) print() paid_hardware = orders.loc[ (orders["status"] == "paid") & (orders["category"] == "hardware"), ["order_id", "customer", "category", "status", "total_usd"], ] print("FILTER_STATUS_CATEGORY") print(paid_hardware.to_string(index=False)) print() customer_match = orders.loc[ orders["customer"].str.contains("a", case=False, regex=False, na=False), ["order_id", "customer", "region"], ] print("FILTER_CUSTOMER_TEXT") print(customer_match.to_string(index=False)) print() print("VERIFY") print(f"priority rows: {len(priority)}") print(f"priority index: {priority.index.tolist()}") print(f"all priority qty >= 10: {priority['qty'].ge(10).all()}") print(f"source rows unchanged: {len(orders)}")