Suggestion for alternate solution

Hi,

as an alternative to the use of apply(), you could maybe add to the instructions that the problem can also be solved using vectorized string methods.

instead of:
def pad_csd(num):
return str(num).zfill(2)

data["class_size"]["padded_csd"] = data["class_size"]["CSD"].apply(pad_csd)

this is also possible:
data["class_size"]["padded_csd"] = data["class_size"]["CSD"].astype(str).str.pad(2,fillchar="0")

8 Likes