TypeError: Int() argument must be a string, a byte-like object or a number, not a 'list'

Screen Link: Learn data science with Python and R projects

Hello guys,I am stuck here and will need help to get going.
My Code:

```for row in moma:
    date = [6]
    if date != "":
        date = int(date)
        row[6] = date
        
# Calculating Artist ages

ages = [0]
for row in moma:
    birth = row[3]
    date = row[6]
    if type(birth) == int:
        age = date - birth
    else:
        age = 0
        ages.append(age)
        
final_ages = []
for age in ages:
    if age > 20:
        final_age = age
    else:
        final_age = "Unknown"
        final_ages.append(final_age)
        

What I expected to happen:
i expected the code to run and submit successfully

what exactly happened:
an error occurred
Replace this line with the output/error

<ipython-input-1-46df82ca44f7> in <module>
     48     date = [6]
     49     if date != "":
---> 50         date = int(date)
     51         row[6] = date
     52 

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
Variables

<!--Enter other details below: -->
how does one solve this? Also, i manually typed the code on the scrip py page because the page did not  reference code from Artworks_clean.csv file. for me to calculate the artist ages with/ Thanks for your time.
1 Like

Hi @onotanharvey77,

For now, I see 2 issues in your code:

  • It should be date = row[6] instead of date = [6],
  • ages = [] instead of ages = [0].

Please let me know if it helped.

Elena thank you, i have corrected the code as you suggested yesterday, but the error persisted.Early this morning, i noticed a duplication of my hand written code, i deleted my hand written code and left the duplicate code. I ran the code and it ran successfully without error (from what i have experienced so far one needs the screen- generated screen 1 code carried over to screen 2 before one can calculate ages and final_ages that will run successfully) , it was when i submitted i got an advice that my ages and final_ages are shorter than expected and i am trying to figure out how to correct it.

1 Like

Finally, i have fixed it, it was indentation problem @ ages.append(age) and final_ages.append(final_age).Thanks for the support,God bless.

1 Like