我已经运行了一系列的代码,它们似乎都运行得很好,直到我走到最后一步。下面是我运行的几个代码:
rds = pd.read_csv('RDS-A.csv')
print(rds.head())
print(rds.shape)
print(rds.describe())
rds_2015 = rds.loc['2015-01-01':'2015-12-31']
print(rds_2015.loc['2015-01-30'])
错误
KeyError Traceback (most recent call last) get_loc(self, key, method, tolerance) 2896 try: -> 2897 return self._engine.get_loc(key) 2898 except KeyError: pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc() KeyError: '2015-01-30'
尝试:
如果要按日期对数据进行切片,则必须使用
datetime
格式。为了简单起见,可以将该列设置为索引。然后您可以轻松地执行rds['2015']
之类的操作来获取所有的值相关问题 更多 >
编程相关推荐