如果不是,则为AttributeError :(“ str对象没有属性'str'”,“发生在索引0”)

时间:2020-04-15 06:49:24

标签: string if-statement attributeerror

我正在尝试根据以下条件用替换的字符串创建一个新列。 我不断收到错误消息: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)

0 个答案:

没有答案