MAP function applied to only one column

Asked

Viewed 21 times

-1

I’m trying to map the value "Others" to a "Career" column, according to some criteria. For example, when the column contains the Recycle Bin or Helper value, I want that value replaced by 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 rotate this command, all other columns are replaced by the NAN value, that is, it is not only the Career column that is affected, but all the others. How to heal?

1 answer

0


I solved with ifs by 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()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.