5/10 Cleaning and Preparing Data in Python - Index Error

Screen Link: Learn data science with Python and R projects

What am I doing wrong here?

My Code:

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

What I expected to happen:
Print out the value under the gender column in row 100.

What actually happened:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-1-729aef00c16a> in <module>
     25     row[5] = gender
     26 
---> 27 print(row[100][5])

IndexError: list index out of range

Hi and welcome to the community!

You should change row for moma in this line:

print(row[100][5])

'cause when you refer to row[100] you refer to the 100th column of the last row which does not exist in our dataset.

P.S.: By the way, you’ve forgotten to include the link to the mission in your question. Please, check these Guidelines if you have any doubts about formatting the technical questions.

Thanks for the clarification! I understood better and got it now.

Oh, no! I previously included the link to my screen, didn’t know I was supposed to remove these chars <–!. I have corrected it, thanks for pointing out that!