Skip to content Skip to sidebar Skip to footer

Datetime Index Keyerror: 'the Label [2000-01-03 00:00:00] Is Not In The [index]'

I have a pandas dataframe generated by dates = pandas.date_range('1/1/2000', periods=8) df = pandas.DataFrame(rd.randn(8, 5), index=dates, columns=['call/put', 'expiration', 'strik

Solution 1:

The documentation provides a number of ways to index a datetime index DataFrame, a few examples:

In [64]:

index
Out[64]:
Timestamp('2000-01-03 00:00:00')
In [65]:

print df.ix[index.to_datetime()]
            call/put  expiration  strike  ask  bid
2000-01-03  0.830035    -0.42598     0.5    0    0
2000-01-03  0.830035    -0.42598     0.6    1    1
2000-01-03  0.830035    -0.42598     0.4    1    1
In [66]:

print df.ix[index]
            call/put  expiration  strike  ask  bid
2000-01-03  0.830035    -0.42598     0.5    0    0
2000-01-03  0.830035    -0.42598     0.6    1    1
2000-01-03  0.830035    -0.42598     0.4    1    1
In [67]:

print df[index.strftime('%m/%d/%y')]
            call/put  expiration  strike  ask  bid
2000-01-03  0.830035    -0.42598     0.5    0    0
2000-01-03  0.830035    -0.42598     0.6    1    1
2000-01-03  0.830035    -0.42598     0.4    1    1

Post a Comment for "Datetime Index Keyerror: 'the Label [2000-01-03 00:00:00] Is Not In The [index]'"