我正在尝试在设定的日期范围之间选择行,但仍然遇到同样的错误。我尝试了这篇文章中描述的所有方法,但没有运气。
Select dataframe rows between two dates
这是我的数据框:
这是我在尝试选择日期时遇到的错误:
Traceback (most recent call last): File "X:/GIS/Projects/scripts/test.py", line 7, in <module>
mask = (df['TransDate'] > '2017-01-15') & (df['TransDate'] <= '2017-12-20') File "C:\Python27\ArcGISx6410.6\lib\site-packages\pandas\core\frame.py", line 1997, in __getitem__
return self._getitem_column(key) File "C:\Python27\ArcGISx6410.6\lib\site-packages\pandas\core\frame.py", line 2004, in _getitem_column
return self._get_item_cache(key) File "C:\Python27\ArcGISx6410.6\lib\site-packages\pandas\core\generic.py", line 1350, in _get_item_cache
values = self._data.get(item) File "C:\Python27\ArcGISx6410.6\lib\site-packages\pandas\core\internals.py", line 3290, in get
loc = self.items.get_loc(item) File "C:\Python27\ArcGISx6410.6\lib\site-packages\pandas\indexes\base.py", line 1947, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas\index.c:4154)
File "pandas/index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas\index.c:4018)
File "pandas/hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12368)
File "pandas/hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12322)
KeyError: 'TransDate'