Skip to content

Instantly share code, notes, and snippets.

@barel-mishal
Last active October 30, 2021 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barel-mishal/8e9c7fe5197bb28eedb4db3a0c71965a to your computer and use it in GitHub Desktop.
Save barel-mishal/8e9c7fe5197bb28eedb4db3a0c71965a to your computer and use it in GitHub Desktop.
Custome day start and end
import pandas
import numpy
import datetime as dt
def custome_days(pd_DateTime64, hour=00, min=00, sec=00):
time_1 = dt.timedelta(hours=00, minutes=00, seconds=00)
time_2 = dt.timedelta(hours=hour, minutes=minute, seconds=second)
return (pd_DateTime64 - (time_2 - time_1))

Inpute

DatetimeIndex(['2021-10-10 07:47:00', '2021-10-10 07:47:00',
               '2021-10-10 07:47:00', '2021-10-10 07:47:00',
               '2021-10-10 07:47:00', '2021-10-10 07:47:00',
               '2021-10-10 07:47:00', '2021-10-10 07:47:00',
               '2021-10-10 07:47:00', '2021-10-10 07:47:00',
               ...
               '2021-10-17 09:07:00', '2021-10-17 09:07:00',
               '2021-10-17 09:07:00', '2021-10-17 09:07:00',
               '2021-10-17 09:07:00', '2021-10-17 09:07:00',
               '2021-10-17 09:07:00', '2021-10-17 09:07:00',
               '2021-10-17 09:07:00', '2021-10-17 09:07:00'],
              dtype='datetime64[ns]', name='Date_Time_1', length=8144, freq=None)

Output

array([0, 0, 0, ..., 8, 8, 8], dtype=int64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment