I have a dataframe df that looks like this:
Customer Revenue Products Cluster
Jon 100 5 A
Janet 225 12 C
Jim 75 2 B
Stacy 95 4 A
John 125 5 B
Bob 325 20 C
Megan 75 2 A
Stacy 95 4 A
and so on for 100k records.
I am trying to return the top 2 percent of Revenue Customers grouped by cluster. I know this doesn't work but I think it gives the overall idea of what I am trying to do:
df.groupby('cluster').len(df['cluster'])/100 <= .2
Trying to get back a dataframe of the top 2 percent of customers by revenue, by cluster.