got a quick question:
Equivalent code in R code:
mutate(states = reorder(states, median(age)))
I have this in Python:
states = ['California', 'New York', 'Texas', 'Florida']
test_df = pd.DataFrame({'states': states,
'median':[36, 25, 30, 28]})
test_df['states'] = test_df['states'].astype('category')
How do i 'reorder' the 'states' column by median column, so the plot X axis will appear in the order of median column.
For example in R, the below is already in order of median_age.
> df <- df %>% mutate(states = reorder(states, median_age))
> df
states median_age
1 California 36
2 New York 25
3 Texas 30
4 Florida 28
> df %>% ggplot(aes(states, median_age)) + geom_bar(stat="identity")