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

Data_Science_Python

Screen Link: <!-- https://app.dataquest.io/m/351/cleaning-and-preparing-data-in-python/4/cleaning-the-nationality-and-gender-columns>

My Code:

for row in moma:
    nationality=row[2]
    open=nationality.replace("(","")
    closed=open.replace(")","")
    row[2]=closed
    
    gender=row[5]
    open=gender.replace("(","")
    closed=open.replace(")","")
    row[5]=closed

What I expected to happen:
Execute properly.

What actually happened:
Giving Error–moma isn’t defined in your code, but we expected it to be list type.

moma isn’t defined in your code, but we expected it to be list type

Hi @mishraashutosh027,

From the error that you have posted, high possibility is that -

  • You did not read the csv file and you have mentioned moma, which is in this case is a file name. The file is expected to be list type
    To read the csv file, use below code and mention the file name as moma
    • from csv import reader
    • opened_file = open(‘artsworks.csv’)
    • reader_file = reader(opened_file)
    • moma_header = list(reader_file[0])
    • moma = list(reader_file[1:])

try this

Thanks!