dimanche 22 novembre 2020

How to filter and classify with time and dates input

I am new in python and trying to solve two problems, hopefully someone can help me:

  1. I have a data, which one of the columns are date format:
    Date                Sales

0   2019-07-01 00:00:00 16.66
1   2019-07-01 02:14:00 17.35
2   2019-07-01 03:17:00 28.78
3   2019-07-01 03:25:00 15.65

24765   2020-03-20 23:13:00     33.21
24766   2020-03-20 23:15:00     36.60
24767   2020-03-20 23:17:00     12.33

I wanted to create a third column where I identify the shift the sales happened:

From 8:00 to 16:00 - 'First Shift'
From 16:00 to 00:00 - 'Second Shift'
From 00:00 to 08:00 - 'Third Shift'
  1. I wanted to create a sum of sales per day and per shift, the result would be similar to:
 Day           Shift     Total Sales

2019-07-01     First       $543.23
2019-07-01     Second      $413.87
2019-07-01     Third       $301.12
2020-03-14     Third       $214.13

I used to work in Excel and I am trying to convert to python.

In Excel I would use if conditions and pivot table, I did an extended research and could not solve so far.

Aucun commentaire:

Enregistrer un commentaire