0

dates, and values are corelated. I am trying to code a function where it filters out all the values in the values array after the given_date. Since the given_date is '2017-09-15 11:40:30', The first two indexes in dates '2017-09-15 07:11:00' ,'2017-09-15 11:25:30' comes before the given_date so the first tow indexes in values is filtered out. Resulting in the Expected Output. How would I be able to do that?

given_date= '2017-09-15 11:40:30'
dates= np.array(['2017-09-15 07:11:00' ,'2017-09-15 11:25:30', '2017-09-15 12:11:10', '2021-04-07 22:43:12', '2021-04-08 00:49:18'])
values= np.array([10,30,44,55,60])

Expected Output:

[44,55,60]

1 Answer 1

3

These dates are actually strings, so you should treat them as dates:

import numpy as np

given_date = np.datetime64('2017-09-15 11:40:30')
dates = np.array([
    '2017-09-15 07:11:00' ,'2017-09-15 11:25:30', '2017-09-15 12:11:10', '2021-04-07 22:43:12', '2021-04-08 00:49:18'
], np.datetime64)
values = np.array([10,30,44,55,60])

# Use comparison operators like you would with numbers
print(values[dates > given_date]) 
Sign up to request clarification or add additional context in comments.

1 Comment

Hey I have another question that is related to this question could u take a look at it possibly: stackoverflow.com/questions/67813476/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.