0

I have a pandas dataframe which has thousands of rows with 4 columns.

Pd=[
    {'Group':'A','serial': 1, 'Name': 'Mark', 'Marks': 700},
 {'Group':'Z','serial': 2, 'Name': 'Sam', 'Marks': 800},
    {'Group':'A','serial': 3, 'Name': 'Harry', 'Marks': 600},
    {'Group':'Z','serial': 4, 'Name': 'Root', 'Marks': 1000}
    ]

Suppose rows are in thousands, I want to arrange 'Marks' column to be arranged in descending order and then select just top row with maximum marks from each group, starting from serial no 1. (Also comment off the code for selecting top 100 rows in same code) Thanks

Result will look like:

Result=[
    {'Group':'Z','serial': 1, 'Name': 'Root', 'Marks': 1000}, {'Group':'A','serial': 1, 'Name': 'Mark', 'Marks': 700}]
mike
  • 7
  • 3

0 Answers0