1
df = {'Name': ['Gabriel', 'João', 'Marcela', 'Augusto', 'Mariana', 'Ana', 'Paula'],
      'Grupo Funcional':  ['Analista','Analista','Analista','Assessor','Diretor','Diretor','Gerente'],
      'Salary': ['1000', '1700', '1200', '600', '2000', '3000', '4000'],
        }

df = pd.DataFrame(df)

display (df)

What i need is the mean of 'Salary' by 'Grupo Funcional', something like that:

Mean Analista = R$ 3.500,00

Mean Diretor = R$ 2.500,00

I know i can get this by .groupby, but this table has another columns like "Place of Work" and "Residence", so i would like a way to filter as many variables i want and get the mean of the Salary

1 Answer 1

1

You can do that with something like the following

df = {'Name': ['Gabriel', 'João', 'Marcela', 'Augusto', 'Mariana', 'Ana', 'Paula'],
      'Grupo Funcional':  ['Analista','Analista','Analista','Assessor','Diretor','Diretor','Gerente'],
      'Salary': [1000, 1700, 1200, 600, 2000, 3000, 4000],
        }

df = pd.DataFrame(df)

df2 = df.groupby("Grupo Funcional").agg({"Salary":"mean"}).reset_index()

print(df2)
  Grupo Funcional  Salary
0        Analista    1300
1        Assessor     600
2         Diretor    2500
3         Gerente    4000
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.