I am trying labelling time like this
df['day-hour'] = ('Day' + (df['hour'] // 24).add(1).astype(str) +
' - ' + (df['hour'] % 24).astype(str))
So, the result will be
customer_id hour day-hour
1 10 Day1 - 10
1 123 Day6 - 3
1 489 Day21 - 9
2 230 Day9 - 14
then I try to group df.groupby(['customer_id','day-hour']).size().unstack(fill_value=0)
and the result is
day-hour Day1 - 10 Day6 - 3 Day21 - 9 Day9 - 14
customer_id
1 1 1 1 0
2 0 0 0 1
The output that I expected is sort by actual days like this
day-hour Day1 - 10 Day6 - 3 Day9 - 14 Day21 - 9
customer_id
1 1 1 0 1
2 0 0 1 0
What code that should I change?