если elif else AttributeError: ("объект '' str 'не имеет атрибута' str '",' произошел с индексом 0 ') - PullRequest
0 голосов
/ 15 апреля 2020

Я пытаюсь создать новый столбец с замененными строками в соответствии с условиями ниже. Я получаю сообщение об ошибке: AttributeError: («объект 'str' не имеет атрибута 'str'", "произошел с индексом 0") Кто-нибудь может мне помочь с ошибкой? Очень ценится!

wage = ['daily', 'hour','month','piece','daily&hour','daily&month','daily&piece','hour&month','hour&piece','month&piece','none']

dict = {'Wage_System': wage}

q2 = pd.DataFrame(dict) 

def get_output(q2):
    if q2['Wage_System'].str.contains('hour'):
        return 'Hourly'
    elif q2['Wage_System'].str.contains('daily'):
        return 'Daily'
    elif q2['Wage_System'].str.contains('month'):
        return 'Monthly'
    elif q2['Wage_System'].str.contains('piece'):
        return 'Piece'

    elif q2['Wage_System'].str.contains('hour') and q2['Wage_System'].str.contains('daily'):
        return 'Mixed'
    elif q2['Wage_System'].str.contains('hour') and q2['Wage_System'].str.contains('monthly'):
        return 'Mixed'
    elif q2['Wage_System'].str.contains('hour') and q2['Wage_System'].str.contains('piece'):
        return 'Mixed'    

    elif q2['Wage_System'].str.contains('daily') and q2['Wage_System'].str.contains('monthly'):
        return 'Mixed'
    elif q2['Wage_System'].str.contains('daily') and q2['Wage_System'].str.contains('piece'):
        return 'Mixed'    

    elif q2['Wage_System'].str.contains('monthly') and q2['Wage_System'].str.contains('piece'):
        return 'Mixed'  

    else:
        return 'Not Specified'

q2['New Wage System'] = q2.apply(get_output, axis=1)
...