String Capitalization

Hi,
I am working on 1st mission in Python for Data Science: Intermediate course. In the 5th step of String Capitalisation. Here, we clean the nationality and gender column. In this, we are supposed to check for the missing values in the gender column and replace it with the text “Gender Unknown/Other”

Below is the correct code:

for row in moma:
gender = row[5]
gender = gender.title()
if not gender:
gender = “Gender Unknown/Other”

row[5] = gender

The code that I am trying raises an error and I don’t understand the reason. Below is the code that I wrote:

for row in moma:
gender = row[5]
gender = gender.title()
if gender == “”:
gender = “Gender Unknown/Other”

row[5] = gender

Please help!

Hi,

I’m also new to the field but the problem I think with the codes above is that there is a boolean variable in from of the if statement which isn’t what it’s suppose to be.

Something like this should suffice;
If gender == " ":
gender = “Gender Unknown/Other”
row[5] = gender

The code you wrote didn’t have a space between the “” in front of the if statement…

I think that should work,
Gracias…