Ciara Spencer
Ciara Spencer

Reputation: 131

Row Count after groupby and agg

I'm trying to get the row count of each LoanRange, right now the dataframe displays the count for "JobsRetained". The sum amount still needs to display for JobsRetained.

jobsByRange_df = ppp_df.groupby(["Industry", "LoanRange"])["JobsRetained"].agg(['count', 'sum'])
jobsByRange_df 

This is the current DataFrame Display

Upvotes: 1

Views: 65

Answers (1)

Ricardo Fantinelli
Ricardo Fantinelli

Reputation: 36

Not sure if this is what you want. Please, try this:

jobsByRange_df = ppp_df.groupby(["Industry", "LoanRange"]).agg(SumJobsRetained=('JobsRetained', 'sum'), CountLoanRange=('LoanRange', 'count'))

jobsByRange_df

If it doesn't work, could you please share your dataframe? It'd be helful to get a precise answer.

Upvotes: 1

Related Questions