【发布时间】:2022-01-17 17:02:07
【问题描述】:
我编写了一个代码(在 pyspark 中适用于数据框 pandas)来绘制历史系列图:以年为单位的数量趋势。在 x 轴上,我输入了月份的名称。我怎样才能正确地而不是按字母顺序排列它们?
谢谢
plt.figure()
pd_filter = df[df["date"] < pd.to_datetime("2021-12-01")].copy()
pd_new = pd.DataFrame(pd_filter.groupby(["Month","Year"])["quantity"].count()).reset_index()
ax = pd_new.set_index("Month").groupby("Year")["quantity"].plot(legend=True, figsize=(10,5), title = "Quantity per Year")
plt.xlabel("Months")
plt.ylabel("Quantity")
plt.show()
【问题讨论】: