So I have this dataframe with labels as stock objects. As index, I have 'return' and 'momentum'. I want to sort stocks according to 'momentum' and then find the average 'return' of the top 50 stocks and the bottom 50 stocks then compare the two.
I can totally do it but my code looks really ugly, to the point that it's embarrassing to share as a backtest.
Can any gurus show me how this can be done gracefully?
Thanks