Faiza
Faiza

Reputation: 1

How to rename a groupby result coulmn in python

I have a code, I want to change the name of "UC" column as "No.of RCA". Please help me in it.

here is the code

    agency.groupby(['Agency']).agg({
'UC':'count',
'Total number of children aged 9 months less to 15 years assessed in this RCA':'sum',
'Total number of children received TCV':'sum',
'nonvaccinated':'sum'})

Upvotes: 0

Views: 67

Answers (2)

Shubham Sharma
Shubham Sharma

Reputation: 71689

You can use DataFrame.rename to rename the columns as required.

Use:

agency.groupby(['Agency']).agg({
'UC':'count',
'Total number of children aged 9 months less to 15 years assessed in this RCA':'sum',
'Total number of children received TCV':'sum',
'nonvaccinated':'sum'}).rename(columns={"UC": "No. of RCA"})

Upvotes: 2

ashishmishra
ashishmishra

Reputation: 389

For renaming column_name we use .rename function:

agency = agency.rename(columns={'UC': 'No.of RCA'})

Upvotes: 2

Related Questions