The following is my code which i am running on a dataframe
def get_day_limit(self):
self.df['day_end'] = np.where(self.df.index == self.df.index.get_loc(dt.strptime(str(self.df.index.date),'%Y-%m-%d')+' '+'15:15:00'),1,0)
The index date and time format is as follows
2020-02-18 09:15:00
2020-02-18 09:30:00
2020-02-18 09:45:00
When the time is equal to 15:15:00 irrespective of the date, i want the self.df['day_end']
to be 1 else 0
but i get the following error:-
> ValueError: time data '[datetime.date(2020, 2, 18) datetime.date(2020,
> 2, 18)\n datetime.date(2020, 2, 18) ... datetime.date(2020, 5, 20)\n
> datetime.date(2020, 5, 20) datetime.date(2020, 5, 20)]' does not match
> format '%Y-%m-%d'
When i had tried it separately, i noticed that the 0 is removed from the month datetime.date
because of which it is unable to read month with %m
i search stack overflow and found that, when we use %Y-%m-%d
format with a hyphen, it removes the zero in the start. Here Python strftime - date without leading 0?.
BUT MY DATA WILL ONLY BE AVAILABLE WITH HYPHEN.
i tried using .date()
but ndarray is non callable object