質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

6313閲覧

pythonのpandasを使用して移動平均を出したい

ultraman

総合スコア12

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2017/04/24 07:21

###前提・実現したいこと

pythonのpandasを使用して移動平均を出したいのですが
'Series' object has no attribute 'rolling'となってしまいます。

--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-112-570094cd89f4> in <module>() ----> 1 s.rolling(window=3, min_periods=3).mean() /Users/user/.pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/pandas/core/generic.py in __getattr__(self, name) 2244 return self[name] 2245 raise AttributeError("'%s' object has no attribute '%s'" % -> 2246 (type(self).__name__, name)) 2247 2248 def __setattr__(self, name, value): AttributeError: 'Series' object has no attribute 'rolling'

###該当のソースコード

python

1import pandas as pd 2s = pd.Series(range(0,10)) 3s.rolling(window=3, min_periods=3).mean()

###試したこと

print(type(s)) for x in dir(s): print(x) --- <class 'pandas.core.series.Series'> T _AXIS_ALIASES _AXIS_IALIASES _AXIS_LEN _AXIS_NAMES _AXIS_NUMBERS _AXIS_ORDERS _AXIS_REVERSED _AXIS_SLICEMAP __abs__ __add__ __and__ __array__ __array_prepare__ __array_priority__ __array_wrap__ __bool__ __bytes__ __class__ __contains__ __delattr__ __delitem__ __dict__ __dir__ __div__ __doc__ __eq__ __finalize__ __float__ __floordiv__ __format__ __ge__ __getattr__ __getattribute__ __getitem__ __getstate__ __gt__ __hash__ __iadd__ __imul__ __init__ __int__ __invert__ __ipow__ __isub__ __iter__ __itruediv__ __le__ __len__ __long__ __lt__ __mod__ __module__ __mul__ __ne__ __neg__ __new__ __nonzero__ __or__ __pow__ __radd__ __rand__ __rdiv__ __reduce__ __reduce_ex__ __repr__ __rfloordiv__ __rmod__ __rmul__ __ror__ __rpow__ __rsub__ __rtruediv__ __rxor__ __setattr__ __setitem__ __setstate__ __sizeof__ __str__ __sub__ __subclasshook__ __truediv__ __unicode__ __weakref__ __xor__ _accessors _add_numeric_operations _agg_by_level _align_frame _align_series _allow_index_ops _at _binop _box_item_values _can_hold_na _check_inplace_setting _check_is_chained_assignment_possible _check_percentile _check_setitem_copy _clear_item_cache _consolidate_inplace _construct_axes_dict _construct_axes_dict_for_slice _construct_axes_dict_from _construct_axes_from_arguments _constructor _constructor_expanddim _constructor_sliced _convert _create_indexer _dir_additions _dir_deletions _expand_axes _from_axes _get_axis _get_axis_name _get_axis_number _get_axis_resolvers _get_block_manager_axis _get_bool_data _get_cacher _get_index_resolvers _get_item_cache _get_numeric_data _get_repr _get_val_at _get_values _get_values_tuple _get_with _iat _iget_item_cache _iloc _index _indexed_same _info_axis _info_axis_name _info_axis_number _init_mgr _internal_names _internal_names_set _is_cached _is_datelike_mixed_type _is_mixed_type _is_numeric_mixed_type _is_view _ix _ixs _loc _make_cat_accessor _make_dt_accessor _make_str_accessor _maybe_box _maybe_cache_changed _maybe_update_cacher _metadata _needs_reindex_multi _protect_consolidate _reduce _reindex_axes _reindex_axis _reindex_indexer _reindex_multi _reindex_with_indexers _reset_cache _reset_cacher _set_as_cached _set_axis _set_is_copy _set_item _set_labels _set_subtyp _set_values _set_with _set_with_engine _setup_axes _slice _stat_axis _stat_axis_name _stat_axis_number _typ _unpickle_series_compat _update_inplace _validate_dtype _values _xs abs add add_prefix add_suffix align all any append apply argmax argmin argsort as_blocks as_matrix asfreq asof astype at at_time autocorr axes base between between_time bfill blocks bool clip clip_lower clip_upper combine combine_first compound compress consolidate convert_objects copy corr count cov cummax cummin cumprod cumsum data describe diff div divide dot drop drop_duplicates dropna dtype dtypes duplicated empty eq equals factorize ffill fillna filter first first_valid_index flags floordiv from_array from_csv ftype ftypes ge get get_dtype_counts get_ftype_counts get_value get_values groupby gt hasnans head hist iat idxmax idxmin iget iget_value iloc imag index interpolate irow is_copy is_time_series isin isnull item items itemsize iteritems iterkv ix keys kurt kurtosis last last_valid_index le loc lt mad map mask max mean median min mod mode mul multiply nbytes ndim ne nlargest nonzero notnull nsmallest nunique order pct_change pipe plot pop pow prod product ptp put quantile radd rank ravel rdiv real reindex reindex_axis reindex_like rename rename_axis reorder_levels repeat replace resample reset_index reshape rfloordiv rmod rmul round rpow rsub rtruediv sample searchsorted select sem set_axis set_value shape shift size skew slice_shift sort sort_index sort_values sortlevel squeeze std strides sub subtract sum swapaxes swaplevel tail take to_clipboard to_csv to_dense to_dict to_frame to_hdf to_json to_msgpack to_period to_pickle to_sparse to_sql to_string to_timestamp tolist transpose truediv truncate tshift tz_convert tz_localize unique unstack update valid value_counts values var view where xs

###補足情報(言語/FW/ツール等のバージョンなど)
pandas==0.17.0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ドキュメント を見ると

pandas.Series.rolling

New in version 0.18.0.

とありますので、pandas の version 0.18.0 以降をお使い下さい。

投稿2017/04/24 07:46

編集2017/04/24 10:23
magichan

総合スコア15898

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ultraman

2017/04/24 15:48

ありがとうございます。 助かりました。 早速バージョンアップしてみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問