How to make a fixed number of groups by percentile from a dataframe in pandas
You can create 20 equal size bins using this.
df['newcol'] = pd.qcut(df.a,np.linspace(.05, 1, 19, 0), duplicates='drop')
Then you can groupby the newcol to find the summary stats of a,b and c columns
df.groupby(['newcol']).mean()
I am looking for a way to make n (e.g. 20) groups in a dataframe by a specific column by percentile. (data type is float). I am not sure if the group by quantile function can take care of this, and if it can, how the code should look like.
There are 3 rows a, b, c
i.e. Data are sorted by column 'a', and make 20 groups

Group 1 = 0 to 5 percentile
Group 2 = 5 to 10 percentile
.
.
.
Group 20 = 95 to 100 percentile.

would there also be a way to find the mean a, b, and c of each group, and sort them into another dataframe?