Skip to content

BUG: Apply ewm to GroupBy object results in duplicate index columns #44696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
matteosantama opened this issue Nov 30, 2021 · 1 comment
Closed
2 of 3 tasks
Labels
Closing Candidate May be closeable, needs more eyeballs Usage Question Window rolling, ewma, expanding

Comments

@matteosantama
Copy link
Contributor

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd

pd.__version__
>>> '1.3.4'

numbers = [1, 2, 3, 4]
colors = ["green", "red", "blue"]
index = pd.MultiIndex.from_product([numbers, colors], names=["numbers", "colors"])
df = pd.DataFrame({"data": range(len(numbers) * len(colors))}, index=index)

df.groupby(level=["colors"]).mean()
>>>         data
colors      
blue     6.5
green    4.5
red      5.5

df.groupby(level=["colors"]).ewm(span=2).mean()
>>>                            data
colors numbers colors          
blue   1       blue    2.000000
       2       blue    4.250000
       3       blue    6.846154
       4       blue    9.650000
green  1       green   0.000000
       2       green   2.250000
       3       green   4.846154
       4       green   7.650000
red    1       red     1.000000
       2       red     3.250000
       3       red     5.846154
       4       red     8.650000

Issue Description

By adding an intermediary .ewm() step to the groupby operation, the resulting DataFrame has a duplicate index column.

Expected Behavior

I would expect consistent behavior whether I apply a .ewm transformation or not.

Installed Versions

INSTALLED VERSIONS

commit : 945c9ed
python : 3.8.12.final.0
python-bits : 64
OS : Darwin
OS-release : 21.1.0
Version : Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.4
numpy : 1.20.0
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 56.0.0
Cython : 0.29.24
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.4
html5lib : None
pymysql : 1.0.2
psycopg2 : None
jinja2 : 3.0.3
IPython : 7.30.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fsspec : 2021.11.1
fastparquet : None
gcsfs : None
matplotlib : 3.5.0
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : 2021.11.1
scipy : 1.7.3
sqlalchemy : 1.4.27
tables : None
tabulate : 0.8.9
xarray : 0.20.1
xlrd : None
xlwt : None
numba : None

@matteosantama matteosantama added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 30, 2021
@phofl
Copy link
Member

phofl commented Dec 1, 2021

@phofl phofl added Closing Candidate May be closeable, needs more eyeballs Usage Question Window rolling, ewma, expanding and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Usage Question Window rolling, ewma, expanding
Projects
None yet
Development

No branches or pull requests

2 participants