Skip to content

BUG: pandas.DataFrame.explode #47739

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
3 tasks done
bigrogerio opened this issue Jul 15, 2022 · 4 comments
Closed
3 tasks done

BUG: pandas.DataFrame.explode #47739

bigrogerio opened this issue Jul 15, 2022 · 4 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@bigrogerio
Copy link

bigrogerio commented Jul 15, 2022

Pandas version checks

  • 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 main branch of pandas.

Reproducible Example

import pandas as pd

df = pd.DataFrame({'A': [[0, 1, 2], 'foo', [], [3, 4]], 'B': 1, 'C': [['a', 'b', 'c'], np.nan, [], ['d', 'e']]})

df.explode('A')

# df is not changed.

Issue Description

When we explode a Dataframe using the method pandas.DataFrame.explode, it doesn`t apply the changes in the dataframe itself. To solve this problem a good way is to insert an "inplace" argument, that is not accepted in the moment.

Expected Behavior


df = pd.DataFrame({'A': [[0, 1, 2], 'foo', [], [3, 4]], 'B': 1, 'C': [['a', 'b', 'c'], np.nan, [], ['d', 'e']]})

df.explode('A')

# df is changed.

Installed Versions

In [2]: pd.show_versions()

INSTALLED VERSIONS

commit : e8093ba
python : 3.9.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-1080-gcp
Version : #87~18.04.1-Ubuntu SMP Fri Jun 10 18:50:42 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.4.3
numpy : 1.23.1
pytz : 2021.3
dateutil : 2.8.2
setuptools : 56.0.0
pip : 22.1
Cython : None
pytest : 5.4.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.0.1
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.02.0
gcsfs : 2022.02.0
markupsafe : 2.1.0
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : 0.17.5
pyarrow : 8.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.6.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
zstandard : None

@bigrogerio bigrogerio added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 15, 2022
@jreback
Copy link
Contributor

jreback commented Jul 15, 2022

-1 on adding inplace
this is an antipattern and going away

@mroeschke
Copy link
Member

Agreed, this is not a bug as explode is not meant to operate inplace. We are removing inplace, so don't think it's worth adding. Closing

@bigrogerio
Copy link
Author

bigrogerio commented Jul 15, 2022

Just a question: wouldn't be worth to make the method "explode" change de dataframe itself?

I raised this issue thinking that explode method should behave like the method "drop", for example.

@mroeschke
Copy link
Member

wouldn't be worth to make the method "explode" change de dataframe itself

Can change via df = df.explode(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants