AttributeError: 'rare' is not a valid function for 'Series' object

AttributeError: 'rare' is not a valid function for 'Series' object

我想问题出在“应用”功能上,但我应该更改什么?:

def value(val,spec_1,spec_2,spec_3,spec_4):
    '''filtering Specific values'''
    if 'DOOm1' in val or 'DOOm2' in val:
        return spec_1
    elif 'DOOm3' in val:
        return spec_2
    elif 'DOOm4' not in val:
        return spec_3
    else:
        return spec_4
data['value'] = data.value.apply(value(val = data['value'],spec_1 ='Noted',spec_2= 'Noted',spec_3 = 'rare',spec_4 = 'DOOm4'))
data= data[data['value'] != 'rare']

我认为您可以使用 lambda 函数传递来自 value 列的值,例如标量:

data['value'] = data.value.apply(lambda x: value(x, spec_1 ='Noted',spec_2= 'Noted',spec_3 = 'rare',spec_4 = 'DOOm4'))