I have a DataFrame with a DateTime index where there are many duplicate index labels (i.e. rows with the same datetime). I want to look at rows with the same datetime. So I have the following
utimes = pd.unique(data.index.tolist())
for time in utimes:
data_now = data.loc[time]
# Do some processing on the data_now
This fails with an example error: KeyError 'the label [2015-02-05 21:54:00+00:00] is not in the [index]'
Just to check that this isn't an issue in the creation of utimes, this fails
data.loc[data.index[0]]
with the same error message. How can this be? Here's what the index looks like
> data.index
<class 'pandas.tseries.index.DatetimeIndex'>
[2015-02-05 21:54:00+00:00, ..., 2015-02-05 23:24:00+00:00]
Length: 457, Freq: None, Timezone: UTC
and
> data.index[0]
Timestamp('2015-02-05 22:24:00+0000', tz='UTC')
Any ideas why I can't use .loc with a data_frame's own index??