Select specific day in an np.array containing datetime

Asked

Viewed 65 times

0

I have a np.array.astype('Datetime[s]') called T with several days at random times. I need to select a few days for separation.

I tried to:

for i in np.arange(MinTime,MaxTime,np.timedelta64(1, 'D')):
    mask = (T > i) & (T < (i + np.timedelta64(1, 'D')))
    print (T[mask])

But adding up a day brings problems because any day i returns part of the later day as well. Obviously, you can fix this, but I ask if there is any more numpy/pandas/python way to select any dates only with the day, something like:

print(T[T == '01-01-2006'])

See that:

print (T[T == np.datetime64('01-01-2006')])

returns only 01-01-2006 THE MIDNIGHT BUT I NEED ALL OCCURRENCES 01-01-2006.

1 answer

0

T[T.strftime("%Y-%m-%d")=='2006-01-01']

or

T[((T-np.datetime64('01-01-2006')).days==0)]

should work

Browser other questions tagged

You are not signed in. Login or sign up in order to post.