0

This problem may be trivial one. I have a dataframe df as follows

DealerID    ZMONTH    ZREGION    Cust_Cat     ZBAS_QTY   ZBAS_VAL
1001        201905    ABC        M            200        750
1001        201906    ABC        N            300        480
1001        201907    NOP        P            800        1156
1002        201905    PQR        M            350        525
1002        201906    PST        M            480        690
1002        201907    SNP        P            200        780

I want to apply df.groupby() so that for each DealerID I get the row that has max() ZBAS_VAL. In other words, the resultant dataframe should look like

DealerID    ZMONTH    ZREGION    Cust_Cat     ZBAS_QTY   ZBAS_VAL
1001        201907    NOP        P            800        1156
1002        201907    SNP        P            200        780

My Approach so far:

df = df.groupby(['DealerID'])['ZBAS_VAL'].max().reset_index()

However, such approach is returning only ZBAS_VAL and DealerID columns. What I want is all other remaining column.

Any clue?

pythondumb
  • 1,187
  • 1
  • 15
  • 30

0 Answers0