I am doing Cohort analysis for my company which consists of 2.5 year data. When constructing Pivot tables for cohort table visualizations, my order of columns get shifted (look at img).Cohort data
I guess problem is in proper naming (I should somehow add another 0 before single digit values).
users['monthnum'] = users.OrderDateTime.apply(lambda x: x.month + 12*(x.year-2016))
users['running_month'] = users.monthnum - users.cohort_monthnum
users.running_month = users.running_month.astype(str) + '-month'
I am a newbie to data analysis in python so I am not sure how to fix this. I know if I just leave last row of code left out (so I am not making it a string #purpose is for naming for employer) cohorts work just fine (as integers are sorted correctly).