Python practice: Precise Indexing & Boolean Masking (.loc vs .iloc)

Chapter 20 · 8 questions · included in full access

  1. Question 1 · easy

    Label access with .loc

    Load "sales.csv". Use .loc[0, "Rep"] to access the sales rep of the first row and print it:

    Solve it in your browser
  2. Question 2 · easy

    Positional access with .iloc

    Load "sales.csv". Use .iloc[0, 0] to access the top-left OrderID cell by integer position and print it:

    Solve it in your browser
  3. Question 3 · easy

    Filter orders by region

    Load "sales.csv". Filter rows where sales["Region"] == "North" into north_orders. Print len(north_orders):

    Solve it in your browser
  4. Question 4 · medium

    Compound filter with bitwise &

    Load "sales.csv". Filter orders where (sales["Region"] == "North") & (sales["Revenue"] >= 30000). Print len(matches):

    Solve it in your browser
  5. Question 5 · easy

    Filter reps using .isin()

    Load "sales.csv". Filter rows where sales["Rep"].isin(["Asha Verma", "Ravi Kumar"]) into top_rep_orders. Print len(top_rep_orders):

    Solve it in your browser
  6. Question 6 · easy

    Filter numeric range with .between()

    Load "sales.csv". Filter orders where sales["Units"].between(10, 20) into mid_vol. Print len(mid_vol):

    Solve it in your browser
  7. Question 7 · medium

    Compound filter with bitwise | (OR)

    Load "sales.csv". Filter orders where (sales["Region"] == "East") | (sales["Region"] == "West"). Print len(coastal):

    Solve it in your browser
  8. Question 8 · medium

    Update cell value with .loc

    Load "sales.csv". Update row 0 revenue to 35000 using sales.loc[0, "Revenue"] = 35000. Print sales.loc[0, "Revenue"]:

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing