I am newish to pandas. I have a dataframe (df) with the columns, height (numeric) and team (string) I'd like to rank the teams by their median height.
Here is what I have done so far
df = old_df.groupby("team")
a=df["height"].agg([np.median])
a=a.sort_values(by=['median'])
a.reset_index(inplace=True)
b=a["team"].tolist()
this outputs a list of the team names (b), in order of median height, which could be converted into a dictionary and used to create a new col of the data frame. I am not sure how to do that, but my intuition is that there is almost certainly a simpler way of doing this.
Can you see a better way?