I am wanting to grab the rows for the highest league a player played for each year. I have ordered each league that I want to compare from lowest to highest with a list I created from my code below.
import pandas as pdprospect = pd.read_html('https://www.baseball-reference.com/register/player.fcgi?id=bishop000hun')[0]levels = ['Rk', 'A-', 'A', 'A+', 'AA', 'AAA', 'MLB']prospect = prospect[['Year', 'Tm', 'Lg', 'Lev', 'PA']][prospect['Lev'].isin(levels)]prospect = prospect.sort_values('Lev', ascending = False).groupby(['Year']).tail(1)However, I generated this output.
Year Tm Lg Lev PA6 2019 Salem-Keizer NORW A- 11715 2022 Eugene NORW A+ 35811 2021 San Jose LAW A 9What I was hoping for was for the 2021 row to get me the row that contained the A+ level instead of the A level. Can anyone assist me as to how to resolve this error? Thanks in advance.