Home > Software design >  How to get maximum value of column "No." with respect to column "Name" in pandas
How to get maximum value of column "No." with respect to column "Name" in pandas

Time:02-02

There are 3 column in a table. In column "Name" there are name and in column "No." there are no. with respect to column "Name" So here, I want to find which is a maximum no. of Jawed, Rahul, Vinay.

Na

Below is the expected result.

enter image description here

CodePudding user response:

Use numpy.where with GroupBy.transform for compare max values by original column:

df['Max no.'] = np.where(df.groupby('Name')['No.'].transform('max').eq(df['No.']), 'Max','')

CodePudding user response:

We get the max_index of No. regarding the Name column :

max_value = df.Name[df['No.'].idxmax()]
  •  Tags:  
  • Related