如何在 python 中按分类顺序排序月份,即一月、二月、三月等......?

Reb*_*cca 2 python dataframe pandas jupyter

我正在创建一个在 x 轴上有“月份”的条形图,但是它们以随机顺序显示,我如何对月份进行逻辑排序,即一月、二月、三月...

这是我的代码...

    plt.figure(figsize=(15,10))
    sns.countplot(x=boeing_df.order_month);
    plt.title('Most Popular Order Month');ype here
Run Code Online (Sandbox Code Playgroud)

TIA

moz*_*way 5

您可以使用order参数countplot并为其提供月份列表。一个方便的方法可能是使用calendar.month_abbr

import calendar
sns.countplot(x=boeing_df.order_month, order=calendar.month_abbr[1:])
Run Code Online (Sandbox Code Playgroud)