I generated a chart, with values for each year, from 2011 to 2015. but the generation of the graph, on the X-axis, the years are grouped according to the values, are not in the correct sequence (2011, 2012, 2013, 2014, 2015). What command can I use to fix, determine that the X-axis is ordered based on the order of years and not on the values of each?
The code looks like this:
#Já que cada linha do dataframe é uma ocorrência registrada, então quais os dias que tiveram a maior ocorrência?
semana = {'Friday': 'Sexta-feira', 'Wednesday': 'Quarta-feira', 'Tuesday': 'Terça-feira', 'Thursday': 'Quinta-feira', 'Monday': 'Segunda-feira', 'Saturday': 'Sábado', 'Sunday': 'Domingo'}
dfbh['dia_da_semana'].replace(semana, inplace=True)
dfbh['dia_da_semana'].value_counts()
The result of value_counts
is:
Friday 16022
Wednesday 14526
Tuesday 14479
Thursday 14354
Monday 14255
Saturday 13883
Sunday 10620
Name: day_day, dtype: int64
Following is plotted with the following code:
dfbh['dia_da_semana'].value_counts().plot(kind = 'bar', figsize=(10, 5), fontsize = 10, color=['b', 'r', 'b', 'r', 'b', 'r', 'b']);
And the graph is generated in the above sequence. I want to change to the normal sequence of the week. Maybe a sort_index()
??