I have a pandas dataframe as follows:
df = pd.DataFrame()
df['Name'] = ['Abby', 'Abby', 'Abby', 'Abby', 'Abby', 'Daniel', 'Daniel', 'Daniel', 'Daniel', 'Daniel']
df['Marks'] = [100, 90, 76, 50, 10, 50, 45, 38, 25, 5]
I want to:
- Find the 40th percentile for each group
- Filter the dataframe such that all the values above the 40th percentile for that group are shown.
So, I have found the 40th percentile for each group using:
df.groupby('Name').quantile(0.4)
The Aim is to get to:
My main issue is that the values for each group are not standardized and so I cannot apply an overall percentile value for the entire dataset.
But all the help I saw regarding filtering a dataframe with a certain value does not do it separately for each group. I have seen the following questions:
Pandas, groupby where column value is greater than x
Pandas Groupby apply function to count values greater than zero
My question essentially builds on a variation of the following question: Calculate Arbitrary Percentile on Pandas GroupBy
Is there a way to do this in Pandas?