I have an algo that calculates the top 10th percentile by calculating the fundamental market cap / book value. The I'm using is:
pf['cap_book'] = (now_fund.market_cap / now_fund.tangible_book_value).apply(lambda x: np.log(x))
cap_book_5 = np.percentile(pf.cap_book, 10)
Next I use:
pf = pf[pf.cap_book < cap_book_5]
To select those stocks that are within the top 10th percentile. What I want to do is filter this more. If there is 100 stocks that fall into the top 10th percentile, I want to just select the top 10. Essentially if the calculated cap_book is < top 10 of the 10th percentile. What is the easiest way to do that?