Python 日期时间索引键错误:';标签[2000-01-03 00:00:00]不在[索引]和#x27;

Python 日期时间索引键错误:';标签[2000-01-03 00:00:00]不在[索引]和#x27;,python,datetime,pandas,Python,Datetime,Pandas,我有一个由 dates = pandas.date_range('1/1/2000', periods=8) df = pandas.DataFrame(rd.randn(8, 5), index=dates, columns=['call/put', 'expiration', 'strike', 'ask', 'bid']) df.iloc[2,4]=0 df.iloc[2,3]=0 df.iloc[3,4]=0 df.iloc[3,3]=0 df.iloc[2,2]=0.5 df=df.a

我有一个由

dates = pandas.date_range('1/1/2000', periods=8)
df = pandas.DataFrame(rd.randn(8, 5), index=dates, columns=['call/put', 'expiration', 'strike', 'ask', 'bid'])
df.iloc[2,4]=0
df.iloc[2,3]=0
df.iloc[3,4]=0
df.iloc[3,3]=0
df.iloc[2,2]=0.5
df=df.append(df.iloc[2:3])
df.iloc[8:9,3:5]=1
df.iloc[8:9,2:3]=0.6
df=df.append(df.iloc[8:9])
df.iloc[9,2]=0.4
从df中,我通过

df4=df[(df["ask"]==0) & (df["bid"]==0)]
在通过df4行执行循环时

for index, row in df4.iterrows():
  print index
  df_upperbound = df.iloc[index]
I get index KeyError:“标签[2000-01-03 00:00:00]不在[index]中。”。 尝试时

for index, row in df4.iterrows():
  print index
  df_upperbound = df.xs[index]
我得到TypeError:“instancemethod”对象没有属性“getitem”。 我使用pandas 0.14.0和python 2.7.7。 如何在df中遍历df4的索引条目?

提供了许多方法来索引
datetime
index
DataFrame
,以下是一些示例:

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