1

I have a pandas Series instance defined as follows:

import pandas as pd
timestamps = [1,2,3,4,5,6,7,8,9,10]
quantities = [1,9,6,6,6,4,4,4,5,2]
series = pd.Series(quantities, index=timestamps)

Is it possible to supply an array of index values and retrieve the quantities at them? And if it is, what's the fastest way of achieving this, please?

For example, if I supply:

timestamps = [1,1,1,4]

I expect the following back from series:

quantities = [1,1,1,6]

Thanks for any help here.

1 Answer 1

1

It is possible:

>>> series[[1,1,1,4]]
1    1
1    1
1    1
4    6
dtype: int64
>>> series[[1,1,1,4]].values
array([1, 1, 1, 6])
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.