You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
0 1 2 3
bar bar one NaN NaN NaN NaN
two -0.361421 -0.696686 -0.746137 -0.053621
baz baz one NaN NaN NaN NaN
two 1.014213 0.575803 0.199990 -0.596995
foo foo one NaN NaN NaN NaN
two -0.337821 0.921825 0.256034 -0.572588
qux qux one NaN NaN NaN NaN
two -0.404824 -1.209763 0.581025 -0.741480
#now set the name to the index
df.index.names=['a','b']
df.groupby(level=0).rolling(window=2).mean()
the result:
0 1 2 3
a
bar NaN NaN NaN NaN
bar -0.361421 -0.696686 -0.746137 -0.053621
baz NaN NaN NaN NaN
baz 1.014213 0.575803 0.199990 -0.596995
foo NaN NaN NaN NaN
foo -0.337821 0.921825 0.256034 -0.572588
qux NaN NaN NaN NaN
qux -0.404824 -1.209763 0.581025 -0.741480
Problem description
multiple index dataframe with index names groupy rolling computing reture wrong index
Expected Output
the return result should keep the original index
Output of pd.show_versions()
In [36]: pd.show_versions()
INSTALLED VERSIONS
commit : b5958ee
python : 3.8.2.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8
In [7]: arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']), np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'])]
In [8]: df = pd.DataFrame(np.random.randn(8, 4), index=arrays)
In [9]: df.groupby(level=0).rolling(window=2).mean()
Out[9]:
0 1 2 3
bar bar one NaN NaN NaN NaN
two 0.093151 -0.867964 0.036143 -0.806151
baz baz one NaN NaN NaN NaN
two 0.061005 0.151558 0.639276 -0.057748
foo foo one NaN NaN NaN NaN
two -0.622565 0.253112 0.678680 0.149919
qux qux one NaN NaN NaN NaN
two -0.672658 -0.938227 0.178649 0.293549
In [12]: df.index.names=['a','b']
In [13]: df.groupby(level=0).rolling(window=2).mean()
Out[13]:
0 1 2 3
a a b
bar bar one NaN NaN NaN NaN
two 0.093151 -0.867964 0.036143 -0.806151
baz baz one NaN NaN NaN NaN
two 0.061005 0.151558 0.639276 -0.057748
foo foo one NaN NaN NaN NaN
two -0.622565 0.253112 0.678680 0.149919
qux qux one NaN NaN NaN NaN
two -0.672658 -0.938227 0.178649 0.293549
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample
the result:
the result:
Problem description
multiple index dataframe with index names groupy rolling computing reture wrong index
Expected Output
the return result should keep the original index
Output of
pd.show_versions()
In [36]: pd.show_versions()
INSTALLED VERSIONS
commit : b5958ee
python : 3.8.2.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8
pandas : 1.1.5
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 20.2.4
setuptools : 50.3.2
Cython : None
pytest : 6.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.2.14
tables : None
tabulate : None
xarray : None
xlrd : 1.1.0
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: