Row Count after groupby and agg

Viewed 49

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

1 Answers

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.

Related