BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

What is problem in this code?

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

    Gender=row[5]
    Gender=Gender.title()
    row[5]=Gender
    if not Gender:
        Gender="Gender Unknown/Other"
        row[5]=Gender
    Nationality=row[2]
    Nationality=Nationality.title()
    if not Nationality:
        Nationality="Nationality Unknown"
        row[2]=Nationality
        `````

I am getting this error?- moma list (<class 'list'>)
- actual + expected

What is happening  in background?

Hi @lakhwinder.sidhuu20,

It looks like you are only assigning your Gender & Nationality variable to row[5] and row[2] for missing values (blank rows) for both nationality and gender.

If you move row[5] = Gender and row[2] = Nationality outside of your if statement this command will be applied to all rows, not just the rows where Gender & Nationality are unknown.

for row in moma:   
    Gender=row[5]
    Gender=Gender.title()
    
    if not Gender:
        Gender="Gender Unknown/Other"
    row[5]=Gender # move this outside of if statement
    
    Nationality=row[2]
    Nationality=Nationality.title()
    if not Nationality:
        Nationality="Nationality Unknown"
    row[2]=Nationality # move this outside of if statement
1 Like

But I have already assigned row[5]=Gender in above code and also inside the if statement.