Code Sample
df.groupby(level=['first_name','last_name']).rolling(window=5)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-35-1ad06da0e074> in <module>()
----> 1 df.groupby(level=['first_name','last_name']).rolling(window=5)#.corr(df['px_last'])
/home/code/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in __getattr__(self, attr)
482 return self[attr]
483 if hasattr(self.obj, attr):
--> 484 return self._make_wrapper(attr)
485
486 raise AttributeError("%r object has no attribute %r" %
/home/code/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in _make_wrapper(self, name)
496 "using the 'apply' method".format(kind, name,
497 type(self).__name__))
--> 498 raise AttributeError(msg)
499
500 # need to setup the selection
AttributeError: Cannot access callable attribute 'rolling' of 'DataFrameGroupBy' objects, try using the 'apply' method
Copy and paste runnable code sample
import pandas as pd
import numpy as np
dates = pd.date_range('20130101',periods=6).append(pd.date_range('20130101',periods=6))
df = pd.DataFrame(np.random.randn(12,2),index=dates,columns=list('AB'))
df.groupby(df.index).rolling(window=5)
Expected Output
The code should result in a pandas.core.window.Rolling object
.
df.groupby(level=['first_name','last_name'])['column'].apply(pd.rolling_mean, 5)
works however according to the documentation this functionality has been deprecated?
output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Linux
OS-release: 3.19.0-56-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_AU.UTF-8
pandas: 0.18.0
nose: 1.3.7
pip: 8.1.1
setuptools: 20.3
Cython: 0.23.5
numpy: 1.10.4
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: 1.3.5
patsy: 0.4.0
dateutil: 2.5.1
pytz: 2016.3
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.5.1
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.4
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext)
jinja2: 2.8
boto: 2.39.0
Comment From: jreback
well you have 2 issues.
1) groupby(..).rolling(..)
is not implemented (it will be in 0.18.1, but is not in 0.18.0), see #12743
2) pd.rolling_corr
is deprecated as the message says, see the whatsnew
so as the mesasge says
df.groupby(..).apply(lambda x: x.rolling(...).corr())
is the soln.