Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
[X] I have checked that this issue has not already been reported.
[X] 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
df = pd.DataFrame(
index=[1, 2],
columns=pd.MultiIndex.from_tuples(
[((1, 2), 'a'), ((3, 4), 'b')], names=['level_0', 'level_1']
),
data=[[1, 2], [3, 4]],
)
df.stack() # This raises ValueError: Names should be list-like for a MultiIndex
Issue Description
Using DataFrame.stack on a dataframe that includes tuple in one of the column levels (stack the non-tuple level) results in an exception. This seems to only happen if the level has a name.
Expected Behavior
We should get something like this:
df.T.unstack().T
(1, 2) (3, 4)
1 a 1.0 NaN
b NaN 2.0
2 a 3.0 NaN
b NaN 4.0
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] 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
Issue Description
Using DataFrame.stack on a dataframe that includes tuple in one of the column levels (stack the non-tuple level) results in an exception. This seems to only happen if the level has a name.
Expected Behavior
We should get something like this:
df.T.unstack().T
Installed Versions