Some setting:
In [1]: import numpy as np In [2]: import pandas as pd In [3]: from datetime import datetime In [4]: dates = [datetime(2011, 1, 2), datetime(2011, 1, 5), datetime(2011, 1, 7), datetime(2011, 1, 8), datetime(2011, 1, 10), datetime(2011, 1, 12)] In [5]: ts = pd.Series(np.random.randn(6), index=dates) In [6]: ts Out[6]: 2011-01-02 -0.412335 2011-01-05 -0.809092 2011-01-07 -0.442320 2011-01-08 -0.337281 2011-01-10 0.522765 2011-01-12 1.559876
Well, now, to answer your first question: a) yes, there are less clunky paths, depending on your intention. It is pretty simple:
In [9]: ts[datetime(2011, 1, 8):] Out[9]: 2011-01-08 -0.337281 2011-01-10 0.522765 2011-01-12 1.559876
This is a slice containing all values ββafter the selected date. You can choose only the first one you like by:
In [10]: ts[datetime(2011, 1, 8):][0] Out[10]: -0.33728079849770815
To your second question, (b) - this type of indexing is a fragment of the original, like other numpy arrays. This is NOT a copy of the original. See this question or many similar ones: Error or function: cloning a numpy w / slicing array
To demonstrate, change the slice:
In [21]: ts2 = ts[datetime(2011, 1, 8):] In [23]: ts2[0] = 99
This modifies the original ts time object, since ts2 is a slice, not a copy.
In [24]: ts Out[24]: 2011-01-02 -0.412335 2011-01-05 -0.809092 2011-01-07 -0.442320 2011-01-08 99.000000 2011-01-10 0.522765 2011-01-12 1.559876
If you need a copy, you can (generally) use the copy method or (in this case) use truncate:
In [25]: ts3 = ts.truncate(before='2011-01-08') In [26]: ts3 Out[26]: 2011-01-08 99.000000 2011-01-10 0.522765 2011-01-12 1.559876
Changing this copy will not change the original.
In [27]: ts3[1] = 99 In [28]: ts3 Out[28]: 2011-01-08 99.000000 2011-01-10 99.000000 2011-01-12 1.559876 In [29]: ts
This example is directly from Wes' Python for Data Analysis. Check this. It's great.