谁能告诉我为什么 df['2005-5-31'] 触发 KeyError 异常?
rng = pd.date_range('2005', '2012', freq='M')
df = pd.DataFrame(randn(len(rng), 3), rng, ['X', 'Y', 'Z'])
df.head()
# works
df.ix['2005-5-31']
df['2005-5-31':'2005-5-31']
# Gives KeyError: u'no item named 2005-5-31'
df['2005-5-31']
使用 df['2000-01-01'] 遵循代码有效。
#multiple rows on a single date
rng = pd.date_range('2000-01-01', '2000-01-3', freq='8H')
df = pd.DataFrame(randn(len(rng), 3), rng, ['X', 'Y', 'Z'])
# works
df['2000-01-01']
X Y Z
2000-01-01 00:00:00 -0.227981 1.927932 -0.518947
2000-01-01 08:00:00 0.486063 -1.255186 0.375075
2000-01-01 16:00:00 -2.313950 0.654384 1.111493