pandas - using 'groupby.count' with agg -


df.head

                populous        continents australia   2.331602e+07        australia brazil      2.059153e+08        south america canada      3.523986e+07        north america china      1.367645e+09         asia france     6.383735e+07         europe 

above first 5 entries of dataframe. want group them continents, want perform statistical analysis. want create new dataframe avg, sum, std of each group's populous count of countries in each group, columns.

new_df =df.groupby('continents')['populous'].agg({ 'avg': np.average, 'sum':np.sum, 'std': np.std}), takes care of 3 columns, don't know how count in there. tried including 'size': count , within agg method, resulted in error.

thank you.

you can use 'size': len or 'size': 'count' work. however, @dsm pointed out, len count missing values whereas 'count' doesn't.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -