I am trying to describe() a column from df but for every unique value in another column.I have the df:
id revenue country 1 128 at 2 130 de 3 132 de 4 134 hu 5 136 at 6 138 at 7 140 hu
I want to pass this :
df[df['Country']=='cz'].net_revenue.describe(percentiles=[0.2,0.4,0.6,0.8,0.9,0.95,0.99,0.999])
But for every unique value in the column Country.
CodePudding user response:
Use groupby.describe
:
out = (df.groupby('country')['revenue']
.describe(percentiles=[0.2,0.4,0.6,0.8,0.9,0.95,0.99,0.999])
)
Output:
count mean std min 20% 40% 50% 60% 80% 90% 95% 99% 99.9% max
country
at 3.0 134.0 5.291503 128.0 131.2 134.4 136.0 136.4 137.2 137.6 137.8 137.96 137.996 138.0
de 2.0 131.0 1.414214 130.0 130.4 130.8 131.0 131.2 131.6 131.8 131.9 131.98 131.998 132.0
hu 2.0 137.0 4.242641 134.0 135.2 136.4 137.0 137.6 138.8 139.4 139.7 139.94 139.994 140.0