samedi 16 mai 2020

AttributeError: ("'str' object has no attribute 'contains'", 'occurred at index duration')

I have a problem with my function and I keep getting the attribute error pasted in the title.

My Code

def conversion(x):
    duration = x[0]

    if duration.str.contains('min'):
        return duration.split()[0]
    elif duration.str.,contains('Season'):
        return duration.split()[0]
    else:
        return duration

df['split'] = df[['duration']].apply(conversion)

The data frame contains a column with the duration of Netflix episodes written as a string. Within the column there is a mix of values in two structures, '1 Season' and '94 mins' as an example.

My function was supposed to read in the value check the string structure and return only the number. Thank you.

Aucun commentaire:

Enregistrer un commentaire