An orders table stores the quantity, the price of one unit and a two-letter country code. A report needs three more columns that can all be worked out from those.
Write add_order_columns(df, country_names).
df has the columns order_id, quantity (whole number), unit_price (number) and country_code (text). country_names is a dictionary from a country code to the country's name, for example {"NO": "Norway"}.
Return a new DataFrame with all the columns of df followed by these three, in this order:
total: quantity times unit_pricesize: the text "large" when total is 100 or more, otherwise "small"country: the name that country_names gives for the row's country_code, or the text "Other" when the code is not a key of the dictionaryThe rows stay in their original order.
df. The caller's table must still have only its four columns afterwards. Work on a copy."large".df["size"][some_mask] = .... Assigning through two sets of square brackets in a row makes pandas warn, and on newer pandas it does not change the table at all.