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
In [2]: df=pd.DataFrame(1, index=range(3), columns=pd.MultiIndex.from_product([['a', 'b'], [1, 2]]))
In [3]: df['c'] =2In [4]: df.stack(0)
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
<ipython-input-4-a437419299b6>in<module>()
---->1df.stack(0)
/home/nobackup/repo/pandas/pandas/core/frame.pyinstack(self, level, dropna)
4500returnstack_multiple(self, level, dropna=dropna)
4501else:
->4502returnstack(self, level, dropna=dropna)
45034504defunstack(self, level=-1, fill_value=None):
/home/nobackup/repo/pandas/pandas/core/reshape/reshape.pyinstack(frame, level, dropna)
513514ifisinstance(frame.columns, MultiIndex):
-->515return_stack_multi_columns(frame, level_num=level_num, dropna=dropna)
516elifisinstance(frame.index, MultiIndex):
517new_levels=list(frame.index.levels)
/home/nobackup/repo/pandas/pandas/core/reshape/reshape.pyin_stack_multi_columns(frame, level_num, dropna)
619# level620level_to_sort=_convert_level_number(0, this.columns)
-->621this=this.sort_index(level=level_to_sort, axis=1)
622623# tuple list excluding level for grouping columns/home/nobackup/repo/pandas/pandas/core/frame.pyinsort_index(self, axis, level, ascending, inplace, kind, na_position, sort_remaining, by)
3673# make sure that the axis is lexsorted to start3674# if not we need to reconstruct to get the correct indexer->3675labels=labels._sort_levels_monotonic()
3676indexer=lexsort_indexer(labels._get_labels_for_sorting(),
3677orders=ascending,
/home/nobackup/repo/pandas/pandas/core/indexes/multi.pyin_sort_levels_monotonic(self)
12751276# indexer to reorder the levels->1277indexer=lev.argsort()
1278lev=lev.take(indexer)
1279/home/nobackup/repo/pandas/pandas/core/indexes/base.pyinargsort(self, *args, **kwargs)
2146ifresultisNone:
2147result=np.array(self)
->2148returnresult.argsort(*args, **kwargs)
21492150def__add__(self, other):
TypeError: unorderabletypes: str() >int()
Problem description
This is even more confusing because df[['a', 'b']].stack(0) (where no mixed dtype is left) results in the same error.
Expected Output
In [13]: df.stack(0)
Out[13]:
120a1.01.0NaNb1.01.0NaNcNaNNaN2.01a1.01.0NaNb1.01.0NaNcNaNNaN2.02a1.01.0NaNb1.01.0NaNcNaNNaN2.0
Output of pd.show_versions()
[paste the output of pd.show_versions() here below this line]
The text was updated successfully, but these errors were encountered:
toobaz
changed the title
DataFrame.stack() raises TypeError on mixed type level
DataFrame.stack() raises TypeError on mixed type level under Python 3
Nov 15, 2017
Very odd indeed. Looking at the stacktrace, what is the value of result when the code breaks? Probably a good starting point to find the bug and patch.
Code Sample, a copy-pastable example if possible
Problem description
This is even more confusing because
df[['a', 'b']].stack(0)
(where no mixed dtype is left) results in the same error.Expected Output
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]The text was updated successfully, but these errors were encountered: