Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this issue exists on the latest version of pandas.
-
I have confirmed this issue exists on the main branch of pandas.
Reproducible Example
So I was writing a function that would take a dictionary similar to the one below (just much larger) and I couldn't figure out how to get explode to handle multi-column explosion in a way that didn't mess up my "ID" column. I ended up doing this weird daisy chain approach of setting the index to my ID column, exploding, and then resetting the index. This approach got me exactly what I wanted but I reread the documentation and realized there was indeed already an approach written for this.
import pandas as pd
# mock data
data = {"ID": ["ID1", "ID2", "ID3"], "FWHM":[[1,2,3], [4,5,6,7], [1]], "AUC":[[1,2,3], [4,5,6,7], [1]]}
df = pd.DataFrame(data)
# my solution that I came up with
df.set_index('ID').apply(pd.Series.explode).reset_index()
# the approach that pandas has in its documentation
df.explode(["FWHM", "AUC"])
Both approaches produce exactly the same results but I noticed the pandas approach was rather slow compared to my method and when testing it, it was almost 2.5x as fast. This isn't by any means ground breaking but I'm curious as the number of columns/rows expands on a DF if this could be a meaningful speed up.
Installed Versions
pandas : 2.0.2
numpy : 1.21.5
pytz : 2022.7
dateutil : 2.8.2
setuptools : 61.2.0
pip : 22.1.2
Cython : 0.29.35
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.5
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.3
numba : 0.55.2
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.2
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.2.0
pyqt5 : None
Prior Performance
No response