我定义了一个小函数,用于计算时间序列的一些摘要统计数据
def health(data):
# remove all nan entries
import pandas
nav_daily = data.dropna()
d = pandas.Series(index=['Valid', 'First', 'Last', 'Months'])
d['Valid'] = nav_daily.size
d['First'] = nav_daily.index[0]
d['Last'] = nav_daily.index[-1]
d['Months'] = nav_daily.resample(rule="M", how="last").size
return d
如果将First和Last注释掉,则此方法有效。我不认为这里有大熊猫的问题。我收到错误消息:
Traceback (most recent call last):
...
d['First'] = nav_daily.index[0]
File "H:\thomas\envPython\L01\lib\site-packages\pandas\core\series.py", line 640, in __setitem__
self._set_with(key, value)
File "H:\thomas\envPython\L01\lib\site-packages\pandas\core\series.py", line 680, in _set_with
self._set_labels(key, value)
File "H:\thomas\envPython\L01\lib\site-packages\pandas\core\series.py", line 691, in _set_labels
% str(key[mask]))
ValueError: ['F' 'i' 'r' 's' 't'] not contained in the index
我正在使用Windows 8.这是Ascii或“vs”等问题吗?