A courier charges a flat £3 for any delivery up to and including 5 km, and £0.75 per km for the whole trip when it's longer. Its table has one row per parcel, and the fee column was added like this:
.apply(fee) hasn't appeared in this chapter. It calls fee once for each value in the column, one at a time, and collects the answers into a new column. That makes it easy to write — but it's a Python loop in disguise, and on five million parcels it is slow. The chapter's way of adding a column is whole-column maths, like df["score"] / 100.
Four rewrites without apply are suggested. Each one starts from the same five-row df, before any fee column exists.
Version A
Version B
Version C
Version D
Which version leaves df["fee"] exactly the same as the apply line does?
Select all that apply.