MAP function applied to only one column

-1

I am trying to map the value "Others" to a "Career" column, according to some criteria. For example, when the column contains the Binder or Helper value, I want this value to be replaced with the Other value. The command below is running without error:

aip['Carreira'] = aip['Carreira'].map({'Chefe de Limpeza': 'Outros', 'Lixeiro': 'Outros', 'Auxiliar de Limpeza': 'Outros', 'Ajudante': 'Outros', 'Carreira Externa': 'Outros' }) 

The problem is that when you run this command, all other columns are replaced by the NAN value, ie not only the Career column being affected, but all others. How to heal?

    
asked by anonymous 09.12.2018 / 15:59

1 answer

0

I solved with ifs, applying a function in the column.

row = aip['Carreira']
def get_description(row):
    if row == 'Ajudante':
        return 'Outros'
    elif row == 'Auxiliar Geral':
        return 'Outros'
    elif row == 'Levantando de copos':
        return 'Outros'
    elif row == 'Motorista':
        return 'Outros'
    elif row == 'Presidente':
        return 'Outros'
    else:
        return row
aip['Carreira'] = aip['Carreira'].apply(get_description)
counts = aip['Carreira'].value_counts()
#explode = (0, 0, 0,0.4, 0)
counts.plot(kind='pie', labels = None, figsize=(11,8), legend=True, autopct='%.2f%%')
plt.show()
    
10.12.2018 / 00:15