I have the following data set of stocks along the columns, dates down the rows(downloaded using Bloomberg's Python API - please ignore fact that they are all 'NaN' - this is just for this portion of the data):
I am trying to extract the Month and Years from the Index in order to later do a pivot:
values['month'] = values['date'].apply(lambda x: x.month)
Where values is the name of the above DataFrame.
However this gives an error: 'KeyError 'date'
Running:
values.index
Looks fine:
DatetimeIndex(['2010-01-01', '2010-01-02', '2010-01-03', '2010-01-23',
'2010-01-24', '2010-01-29', '2010-01-30', '2010-01-31',
'2010-02-13', '2010-02-14',
...
'2017-08-12', '2017-08-27', '2017-08-31', '2017-09-01',
'2017-09-03', '2017-09-09', '2017-09-24', '2017-09-29',
'2017-09-30', '2017-10-01'],
dtype='datetime64[ns]', name='date', length=593, freq=None)
So I am just wondering what is going wrong and why I don't seem able to access the actual index here?
