2

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 so i can have fixed array len (because i have other zipped arrays but they differ in array length)

this is what i have:

start = np.datetime64('2016-06-17T15:00')
stop = np.datetime64('2016-06-19T15:00')

index, temp = sensor_cal.get_arrays('ParsedData/parsed.csv')
print(index)
print(temp)
index2 = index[start:stop] /////////////This doesn't work
print(index2)

How can i define a time window like this.... My objective is to get same length arrays in the same time window (because they were previously frequency normalized) and then make a graph where xAxis is time and the various series correspond to the multiple temperature sensor arrays

My error:

['2016-06-17T13:23:59.000000000' '2016-06-17T13:24:59.000000000' '2016-06-17T13:25:59.000000000' ..., '2016-06-20T09:55:59.000000000' '2016-06-20T09:56:59.000000000' '2016-06-20T09:57:59.000000000'] [[
nan] [ nan] [ nan] ..., [ 25.54 ] [ 25.56333333] [ 25.59333333]] Traceback (most recent call last): File "main_cal.py", line 10, in index[start:stop] IndexError: failed to coerce slice entry of type numpy.datetime64 to integer

1
  • In index[start:stop], start and stop must be integers, indexes to positions in the array, e.g. index[2:5]. They are not values. You may need to review what indexing and slicing does in numpy (or for that matter Python lists). Commented Jun 22, 2016 at 17:38

1 Answer 1

3

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 pd
temp = 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.690170
2016-01-19   -0.638598
2016-01-20    0.231680
2016-01-21   -0.202787
2016-01-22   -1.333620
2016-01-23    1.525161
2016-01-24   -0.908140
2016-01-25    0.493663
2016-01-26   -1.768979
2016-01-27    0.147327
...
Sign up to request clarification or add additional context in comments.

Comments

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.