Skip to content
Advertisement

Excel VBA to Python code (Filter function)

I’m new to python. Some help would be great, thanks in advance too. I am trying to get the various average salary based on Units.

In Excel, I would do =AVERAGE(FILTER(B:B,A:A=D3)). Where Column B is all the individual salaries and Column A is the various Unit.

I have managed to do an array of the different units:

DiffUnits = df["Unit"].unique()

My data:

Units Salary
IT 500
Math 3000
Math 1200
Science 700
IT 2000
Science 1800

Expected result (In the form of a table, if possible):

Units AverageSalary
IT 1250
Math 2100
Science 1250

Advertisement

Answer

JavaScript

gives you:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement