0
I generated a chart with values for each year from 2011 to 2015. but the graph generation, on the X axis, the years are grouped according to the values, not in the correct sequence (2011, 2012, 2013, 2014, 2015). Which command can I use to fix, determine that the x-axis is ordered based on the order of the years and not on the values of each?
The code goes 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: dia_da_semana, dtype: int64
In the sequence is plotted a graph 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 command sort_index()
?
Without putting an example of how you declared variables it is difficult to know. Use a [mcve] that this will help someone to give an answer.
– Guto
Guto grateful for the observation and the link to read the example content that should be followed.
– Ricardo Storck
I must say that your question is much better, however, your data is not stated (you just show the result), as well as you are not with a complete header, and it takes a little imagination to get your result. But this is already better than before. I recommend another edition, now with the proper formatting. I’m seeing it in one break and another.
– Guto