【发布时间】:2016-03-17 21:07:13
【问题描述】:
我不知道为什么 pandas 会在这个数据帧上抛出一个越界的索引:
SC7a 2009 2010 2011 2012 2013 2014
Region 10 10.1 10.6 11.1 11.6 9.7 10.8
Georgia 7.5 7.4 7.8 7.6 7.2 7.1
我所做的只是打电话:
df.ix[:, 2014]
我得到这个错误:
IndexError: index 2014 is out of bounds for axis 0 with size 6
请注意,调用 loc 可以正常工作:
df.loc[:, 2014]
SC7a
Region 10 10.8
Georgia 7.1
Name: 2014, dtype: float64
这是一个错误吗? df.loc 和 df.ix 不应该与这些数据互换吗?
【问题讨论】:
-
print df.columns是什么? -
索引([2009, u'2010', u'2011', 2012, 2013, 2014], dtype='object')
标签: python pandas indexing dataframe