-2

Here is my Data:

                 Rev
Project Emp         
A       dave    5000
        Ron    21000
        Lily   12000
B       Maya   15000
        Jon    34000
        Alex   31000
C       Allen  18000
        Ji     10000
        Shan   28000

I need to find out the employee name of the highest Rev collector per project. The output should contain Employee's name and the Rev both. How can I do that in Pandas?

petezurich
  • 9,280
  • 9
  • 43
  • 57
Rashida
  • 401
  • 7
  • 18

3 Answers3

2

Here is one way to do it

df[df['Rev'].eq(df.groupby('Project')['Rev'].transform('max'))]


    Project     Emp     Rev
1         A     Ron     21000
4         B     Jon     34000
8         C     Shan    28000
Naveed
  • 11,495
  • 2
  • 14
  • 21
0

Try this:

df.merge(df.groupby('Project').agg({'Rev': max}), on=['Project', 'Rev'])

Output:

    Project Emp Rev
0   A   Ron 21
1   B   Jon 34
2   C   Shan    28
bpfrd
  • 945
  • 3
  • 11
0

You can use Pandas groupby to group the underlying data on one or more columns and estimate useful statistics like count, mean, median, min, max etc.

then you can get the maximum value of rev :

df.groupby('Project')['Rev'].max()