How to select and rename the sub column and remove the main column from the pandas dataframe

Solution for How to select and rename the sub column and remove the main column from the pandas dataframe
is Given Below:

I am working with pandas dataframe. I have written a code using custom aggregation.

import pandas as pd
from functools import reduce

data = {'item': ['d1','d1','d1','d1','d1','d1','d1','d1','d1','d1'], 'price': [65,52,93,74,46,67,62,50,49,41]}
df = pd.DataFrame(data)

def pass_percent(series):
    obtained_total=0
    grand_marks=0
    for mark in series:
        if mark>=35:
            obtained_total = obtained_total + mark
            grand_marks = grand_marks + 1
    return (obtained_total/(grand_marks*100))*100


df1 = df.groupby('dept').agg({'marks': ['sum', pass_percent]})

print(df1)

The output is like

           marks
       sum     pass_percent
dept
d1     599         59.9

What I what is to have a dataframe like this. What to do this?

       total     final_pass_percent
dept
d1     599         59.9

You can use named tuples in agg() method:

df1=df.groupby('item').agg(total=('price','sum'),final_pass_percent=('price',pass_percent))

OR in 2 steps after aggregration change the column names:

df1=df.groupby('item').agg({'price': ['sum', pass_percent]})
df1.columns=['total','final_pass_percent']

output of df1:

        total   final_pass_percent
item        
d1      599     59.9