October 2017
Intermediate to advanced
532 pages
16h 10m
English
Take a look at the DataFrame output from step 7. Did you notice that the months are in alphabetical and not chronological order? Pandas unfortunately, in this case at least, orders the months for us alphabetically. We can solve this issue by changing the data type of Month to a categorical variable. Categorical variables map all the values of each column to an integer.
We can choose this mapping to be the normal chronological order for the months. Pandas uses this underlying integer mapping during the pivot method to order the months chronologically:
>>> week4a = week4.copy()>>> month_chron = week4a['Month'].unique() # or use drop_duplicates>>> month_chronarray(['Jan', 'Feb', 'Mar', 'Apr'], dtype=object)>>> week4a['Month'] ...
Read now
Unlock full access