Python practice: Precise Indexing & Boolean Masking (.loc vs .iloc)
Chapter 20 · 8 questions · included in full access
Question 1 · easy
Label access with .loc
Solve it in your browserLoad
"sales.csv". Use.loc[0, "Rep"]to access the sales rep of the first row and print it:Question 2 · easy
Positional access with .iloc
Solve it in your browserLoad
"sales.csv". Use.iloc[0, 0]to access the top-left OrderID cell by integer position and print it:Question 3 · easy
Filter orders by region
Solve it in your browserLoad
"sales.csv". Filter rows wheresales["Region"] == "North"intonorth_orders. Printlen(north_orders):Question 4 · medium
Compound filter with bitwise &
Solve it in your browserLoad
"sales.csv". Filter orders where(sales["Region"] == "North") & (sales["Revenue"] >= 30000). Printlen(matches):Question 5 · easy
Filter reps using .isin()
Solve it in your browserLoad
"sales.csv". Filter rows wheresales["Rep"].isin(["Asha Verma", "Ravi Kumar"])intotop_rep_orders. Printlen(top_rep_orders):Question 6 · easy
Filter numeric range with .between()
Solve it in your browserLoad
"sales.csv". Filter orders wheresales["Units"].between(10, 20)intomid_vol. Printlen(mid_vol):Question 7 · medium
Compound filter with bitwise | (OR)
Solve it in your browserLoad
"sales.csv". Filter orders where(sales["Region"] == "East") | (sales["Region"] == "West"). Printlen(coastal):Question 8 · medium
Update cell value with .loc
Solve it in your browserLoad
"sales.csv". Update row 0 revenue to35000usingsales.loc[0, "Revenue"] = 35000. Printsales.loc[0, "Revenue"]:
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing