LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

String Capitalization for Data Cleaning Unit

https://app.dataquest.io/m/351/cleaning-and-preparing-data-in-python/5/string-capitalization

for row in moma: 
    # clean gender values
    gender = row[5]
    gender = gender.title()
    if not gender:
        gender = 'Gender Unknown/Other'
    row[5] = gender
    
    # clean nationality values
    nationality = row[2]
    if not nationality:
        nationality = 'Nationality Unknown'
    row[2] = nationality

What I expected to happen: For this unit I am capitalizing the values for Gender and Nationality from the Moma data and replacing unknown variables with strings. However, I when I submit my code, the moma list is not passing the testcase.

What actually happened: The variable is flagged but it doesn’t show the error in the list.

for row in moma: 
    # clean gender values
    gender = row[5]
    gender = gender.title()
    if not gender:
        gender = 'Gender Unknown/Other'
        row[5] = gender
    
    # clean nationality values
    nationality = row[2]

Something is missing here…
nationality= nationality.title() # This is missing in your code …
So the correct code should be

    nationality= nationality.title() # This is missing in your code .....
    if not nationality:
        nationality = 'Nationality Unknown'
    row[2] = nationality
2 Likes

I’m receiving the same error but my code is correct, i don’t know how to paste it here to show you, but I have gone over it and it is exactly the same as the solution,

Thank you for pointing that out!