How To Slice Numpy Datetime64 Array
I have a python zip with 2 arrays zipped = zip(array1[], array2[]) Where array1 is of type numpy.datetime64[] adn array2 is a temperature I want to make a time window in 1st array
Solution 1:
You can use pandas
indexing which is designed for this. 'series' is a 1d array with an index attached. With reference to Wes McKinney's Python for Data Analysis:
import pandas as pdtemp= np.random.randn(366)
time_series = pd.Series(temp,index=np.arange(np.datetime64('2015-12-19'),np.datetime64('2016-12-19')))
start = np.datetime64('2016-01-17T15:00')
stop = np.datetime64('2016-06-19T15:00')
time_series[start:stop]
Output:
2016-01-18 -0.6901702016-01-19 -0.6385982016-01-20 0.2316802016-01-21 -0.2027872016-01-22 -1.3336202016-01-23 1.5251612016-01-24 -0.9081402016-01-25 0.4936632016-01-26 -1.7689792016-01-27 0.147327...
Post a Comment for "How To Slice Numpy Datetime64 Array"