BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

When we get attribute error?

https://app.dataquest.io/m/351/cleaning-and-preparing-data-in-python/6/errors-during-data-cleaning

    # check that we don't have an empty string
    if date != "":
        date = date.replace("(", "")
        date = date.replace(")", "")
        date = int(date)
    return date
 
for row in moma:
    BeginDate=row[3]
    EndDate=[4]
    row[3]= clean_and_convert(BeginDate)
    row[4]=clean_and_convert(EndDate)```

Error i am getting:AttributeErrorTraceback (most recent call last)
<ipython-input-1-57bc43215caa> in <module>()
     11     EndDate=[4]
     12     row[3]= clean_and_convert(BeginDate)
---> 13     row[4]=clean_and_convert(EndDate)

<ipython-input-1-57bc43215caa> in clean_and_convert(date)
      2     # check that we don't have an empty string
      3     if date != "":
----> 4         date = date.replace("(", "")
      5         date = date.replace(")", "")
      6         date = int(date)

AttributeError: 'list' object has no attribute 'replace'

I think you meant row[4] here. As it is right now, it makes EndDate a list with one element, which is why you’re getting the attribute error.

Thanks, that was blunder mistake