私はmoving_average
と呼ばれるpython pandaシリーズを持っています。このpython pandaの最後の要素にアクセスする系列
moving_average = df['score'].rolling(window=period).mean()
私はシリーズmoving_average
の最後の要素を取得したいと思います。これは私がやったことです。
moving_average = df['score'].rolling(window=period).mean()[-1]
残念ながら、次のエラーが発生しました。
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py", line 601, in __getitem__
result = self.index.get_value(self, key)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2477, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas\_libs\index.pyx", line 98, in pandas._libs.index.IndexEngine.get_value
File "pandas\_libs\index.pyx", line 106, in pandas._libs.index.IndexEngine.get_value
File "pandas\_libs\index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 759, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 765, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: -1
私はそうパンダが故にKeyError例外存在しない-1としてラベルインデックスキーを探している、PythonのV3.6
を忘れないでくださいLOL :-) – Wen