#136-11, Data Cleaning Walkthrough - Inserting DBN Fields

I got stuck at problem 136-11, Data Cleaning Walkthrough course. Thank you for taking a look at my question.
Screen Link:

My Code:

data["class_size"]["padded_csd"] = data["class_size"]["CSD"].apply(lambda x: str(x).zfill(2) if len(str(x)) == 1 else x)

data["class_size"]["DBN"] = data["class_size"]["padded_csd"] + data["class_size"]["SCHOOL CODE"]

data["class_size"]["DBN"].head(15)

What I expected to happen:
I expect DBN column will be formed by combining padded_csd and SCHOOL CODE columns

DBN column should display like this:
DBN
01M015
19M022
02M016
99M025

What actually happened:
I got this error popped up.

TypeError: unsupported operand type(s) for +: 'int' and 'str'

Below is the DataQuest answer to the question

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

data[“class_size”][“padded_csd”] = data[“class_size”][“CSD”].apply(pad_csd)
data[“class_size”][“DBN”] = data[“class_size”][“padded_csd”] + data[“class_size”][“SCHOOL CODE”]
print(data[“class_size”].head())

In your lambda function you write:

data["class_size"]["padded_csd"] = data["class_size"]["CSD"].apply(lambda x: str(x).zfill(2) if len(str(x)) == 1 else x)

I think the problem is, you’re else statement should also convert the variable x to a string. So it should read:

else str(x)

at the end of your lambda function.

This will convert the number to a string so you can concatenate properly.

Ahh I see, it actually worked now. Thank you very much!