gpt4 book ai didi

python - Pandas 错误 : "pandas.hashtable.PyObjectHashTable.get_item"

转载 作者:行者123 更新时间:2023-11-28 17:38:09 26 4
gpt4 key购买 nike

我看到 Pandas 0.15.2 在 Python 3.4.2 上有一些奇怪的行为。

首先,我毫无问题地导入数据:

import pandas as pd

# import the data
hourly = pd.read_csv("fremont_bridge_data.csv", index_col='Date', parse_dates=True)
weekly = hourly.resample('w','sum')

但是在尝试访问时,我遇到了一些奇怪的行为。这很好用:

In[289]:   weekly['2013-12']
Out[289]:
northbound southbound total
Date
2013-12-01 5053 5480 10533
2013-12-08 5432 5836 11268
2013-12-15 5381 5760 11141
2013-12-22 5182 5455 10637
2013-12-29 3118 3567 6685

这失败了:

In[290]:   weekly['2013-12-29']
Traceback (most recent call last):

File "<ipython-input-290-96e181f8ff0a>", line 1, in <module>
weekly['2013-12-29']

File "C:\Anaconda\envs\py34\lib\site-packages\pandas\core\frame.py", line 1780, in __getitem__
return self._getitem_column(key)

File "C:\Anaconda\envs\py34\lib\site-packages\pandas\core\frame.py", line 1787, in _getitem_column
return self._get_item_cache(key)

File "C:\Anaconda\envs\py34\lib\site-packages\pandas\core\generic.py", line 1068, in _get_item_cache
values = self._data.get(item)

File "C:\Anaconda\envs\py34\lib\site-packages\pandas\core\internals.py", line 2849, in get
loc = self.items.get_loc(item)

File "C:\Anaconda\envs\py34\lib\site-packages\pandas\core\index.py", line 1402, in get_loc
return self._engine.get_loc(_values_from_object(key))

File "pandas\index.pyx", line 134, in pandas.index.IndexEngine.get_loc (pandas\index.c:3807)

File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:3687)

File "pandas\hashtable.pyx", line 696, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12310)

File "pandas\hashtable.pyx", line 704, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12261)

KeyError: '2013-12-29'

有什么想法吗?这也失败了:weekly[weekly.index[0]],似乎不应该

数据在这里: https://github.com/sergeyf/Python_data_science_class/blob/master/code/data/fremont_bridge_data.csv

谢谢。

最佳答案

我打开了一个错误报告,得到了这样的回复:

see docs here: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#datetimeindex-partial-string-indexing

partial string indexing is for slices only otherwise it tried column selection

希望这对 future 迷茫的人有所帮助!

关于python - Pandas 错误 : "pandas.hashtable.PyObjectHashTable.get_item",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28310429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com