Sort by month in a plot

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phantom2000
    New Member
    • Oct 2016
    • 3

    Sort by month in a plot

    I am using the following code to plot a graph.

    Code:
    import pandas as pd
    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import folium
    from folium import plugins
     
    crime_data = pd.read_csv('~/Desktop/Assignments/Python/crime_data_sw_police_2021.csv')
    crime_data = crime_data.iloc[:,[1,4,5,9,10]]
    
    crime_data = crime_data.dropna() # Removing rows with null values
     
    count = dict(crime_data["Month"].value_counts())
    x = list (count.keys())
    y = list (count.values())
    plt.figure(figsize = (8,6))
    plt.title(label = "Crime Rate by Month")
    plt.ylabel("Number of Crimes")
    plt.xlabel("Month")
    plt.plot(x,y)
    plt.show()
    However, I get the plot like below and I want to sort it so that the Months are listed as Jan, Feb, March etc. Plot: https://prnt.sc/L8ql76ruULz-

    How can I do that? Thanks in advance.
Working...