My multi-indexed data frame is as follows:
df.head()
Output
Unit Timestamp
1 2016-06-01 00:00:00 225894.9
2016-06-01 01:00:00 225895.9
2016-06-01 02:00:00 225896.9
2016-06-01 03:00:00 225897.9
2016-06-01 04:00:00 225898.9
df.tail()
Output
Unit Timestamp
16 2016-06-30 18:00:00 150543.1
2016-06-30 19:00:00 150544.1
2016-06-30 21:00:00 150546.1
2016-06-30 22:00:00 150547.1
2016-06-30 23:00:00 150548.1
That is, one month's worth of hourly data for 16 units.
I want to pick out one day's data for a given unit. I have an array of the days that appear in the dataframe,
days = array([datetime.date(2016, 6, 1), datetime.date(2016, 6, 2),
datetime.date(2016, 6, 3), datetime.date(2016, 6, 4),...
etc etc
If I do df.ix[5,'2016-06-10']
, I get exactly what I want, that is the day's for unit 5 that date
Output
Timestamp
2016-06-10 00:00:00 152364.6
2016-06-10 01:00:00 152365.7
2016-06-10 02:00:00 152366.6
...
2016-06-10 21:00:00 152386.6
2016-06-10 22:00:00 152386.6
2016-06-10 23:00:00 152387.6
But the same indexing doesn't seem to work when I have a datetime.date object instead of a string. For example:
tenth = days[9]
evaulates to datetime.date(2016, 6, 10)
, so far so good.
However when I do df.ix[5,tenth]
I get "KeyError: u'no item named 2016-06-10'"
So, the '2016-06-10'
"does what I mean" and returns all the data on that day. How can I do the same if with a datetime.date?