This is a continuation of my Sales Report in Pandas post and it begins with the final table from it. Here it is for one random customer.
report[report['CustomerID'] == 12347.0]
It represents an activity of this particular customer for the whole available date range aggregated by month. You can see that this activity is not regular.
First, I want to add a flag whether or not customer was active in the previous month.
report['active_prev'] = (report.sort_values(by=['month'], ascending=True)
This hard stuff is something like a window function in sql. Because I have many customers I have to somehow say to…