BasicsPandasFilteringMetaAmazonUber
Problem
Implement filter_orders(df, min_amount=100.0) returning only rows where status == 'completed' and amount > min_amount (strictly greater), with a clean 0-based reset index.
Why It Matters: Compound boolean filtering with .loc and .reset_index(drop=True) is the #1 everyday Pandas operation in data cleaning and analytics pipelines.
Function Signature
import pandas as pd
def filter_orders(df: pd.DataFrame, min_amount: float = 100.0) -> pd.DataFrame:
Sample Input & Output
Example 1: Standard Filter (min_amount = 100.0)
Input:
| order_id | status | amount |
|---|---|---|
| 1 | completed | 150.0 |
| 2 | pending | 200.0 |
| 3 | completed | 100.0 |
| 4 | completed | 250.0 |
Parameter: 100.0 |
Expected Output:
| order_id | status | amount |
|---|---|---|
| 1 | completed | 150.0 |
| 4 | completed | 250.0 |
Explanation: Rows 1 (150.0) and 4 (250.0) pass both filters; row 2 is 'pending' and row 3 equals 100.0 (not strictly greater).
Example 2: No Rows Match (Empty DataFrame)
Input:
| order_id | status | amount |
|---|---|---|
| 1 | cancelled | 500.0 |
| 2 | completed | 50.0 |
Parameter: 100.0 |
Expected Output:
| order_id | status | amount |
|---|
Explanation: When no row satisfies both conditions, returns an empty DataFrame preserving the original columns.
Constraints & Edge Cases
- Return a filtered DataFrame with reset index.
- Use strict inequality
amount > min_amount(not>=). - Always chain
.reset_index(drop=True)so row indices are0, 1, ....
Constraints & Evaluation Criteria
- Return a filtered DataFrame with reset index.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
4 orders
Expected Output / Criteria
1 matching order