2021年1月25日星期一

Ordering months on x-axis in pandas bar chart

I am trying to order my bar chart from Jan-Dec instead of highest count of lowest, I'm sure there is an easy fix but I cannot find it. Currently, my graph is ordering itself on the values and not the months on the x-axis. The first line of code I added a month column. The second I found the counts of each month. The third I plot in bar chart.

df1['Month Added'] = pd.DatetimeIndex(df1['Date Added']).month_name()  df_month = df1['Month Added'].value_counts()  df_month.plot(kind='bar')  

Output is enter image description here

I tried the following but no luck.

df_month.Month.value_counts().loc[['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']].plot(kind='bar')    
https://stackoverflow.com/questions/65894499/ordering-months-on-x-axis-in-pandas-bar-chart January 26, 2021 at 08:58AM

没有评论:

发表评论