0

I have a data set like this .

Sector   Salary Paid Employer        Job Title  
College $105,595.39 Algonquin College   Professor   
university $208,456,897, harvard university Professor
 College    $200,000,000 csi College    Professor   
university $50,000, ISU university Professor
  College   $60,000.39 Algonquin College    Professor   
university $258,645,789, ALU university Professor

I am trying to groupby based in the seector i.e. college or universityI have grouped by by like

universities = df[ df['Employer'].str.contains('Univ',regex=True) ]
university_group= universities.groupby('Employer'). 

After this i try to find the average of every individual university

average_salary_university=university_group['Salary ($)'].agg(np.mean)

This give the individual average salary of university. I am trying to find the lowest and highest average salary of a university from a list. and For each, how many employees do they have making over $100,000CAN?

I try to this

minimum= (average_salary_university).values.argmax()
df[df[minimum]]

But it is not working. Can somebody help me please

jenna
  • 87
  • 1
  • 6
  • Could you paste a larger sample of the dataframe and expected output? – yatu Sep 24 '19 at 14:39
  • i have added the input. Regrading the output i need to find a name of a university that has a lowest average salary among others – jenna Sep 24 '19 at 14:43

1 Answers1

0

Use idxmin to get the minimum index value, since the university is in the index after groupby and agg

min_uni = average_salary_university.idxmin()
print(min_uni)
# ISU University

Note: Please refer to here for good reproducible pandas example. It would be much easier if you could provide the dataframe like this:

df = pd.DataFrame(columns=['Sector', 'Salary Paid', 'Employer', 'Job Title'],
                  data=[['College', '$105,595.39', 'Algonquin College', 'Professor'],
                        ['University', '$208,456,897', 'harvard University', 'Professor'],
                        ['College', '$200,000,000', 'csi College', 'Professor'],
                        ['University', '$50,000', 'ISU University', 'Professor'],
                        ['College', '$60,000.39', 'Algonquin College', 'Professor'],
                        ['University', '$258,645,789', 'ALU University', 'Professor']
                        ])
henrywongkk
  • 1,840
  • 3
  • 17
  • 26