Skip to content
Advertisement

Dividing 24h into working shifts in Python Pandas

I am dealing with dividing a day into working shifts. Let’s have a look at my sample code:

I’d like to divide the time into 3 shifts, 00:00 to 08:00 is Shift1, 08:00 to 16:00 will be Shift2 and till 00:00 will be Shift3.

What I get is true, but I would like to know if there is any elegant and easier way to do it?

JavaScript

the dataframe looks like:

JavaScript
JavaScript
JavaScript

Advertisement

Answer

Try to create SHIFTS column before then pivot your dataframe:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement