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 [170]: importpandasIn [171]: importnumpyasnpIn [172]: importitertoolsIn [173]: index=pandas.MultiIndex.from_tuples([tfortinitertools.product(['foo', 'bar'], [0, 1] , ['a', 'b'])])
In [174]: df=pandas.DataFrame(np.random.randn(8,2), columns=['A', 'B'], index=index)
In [175]: dfOut[175]:
ABfoo0a-1.6271.301b-494.049m120.371mfoo1a955.212m580.450mb-55.806m169.247mbar0a266.666m246.100mb806.406m894.707mbar1a-1.319475.675mb638.371m409.483m
Unstacking a single level works fine.
In [176]: df.unstack(level=[1])
Out[176]:
AB0101bara266.666m-1.319246.100m475.675mb806.406m638.371m894.707m409.483mfooa-1.627955.212m1.301580.450mb-494.049m-55.806m120.371m169.247m
Trying to unstack multiple level does not work as expected.
Looks like when handling multiple levels the unstack are applied consecutively, ok for the first unstack, but following ones should have level adapted internally, which does not seem to happen.
First example tries to unstack level 0 and 1 but level 0 and 2 get unstacked.
Second example, idea is to unstack level 1 and 2 but this gives an error, since after level 1 is unstacked, there is no level 2 any more this became level 1 - see also last example.
Let`s create a dataframe first.
Unstacking a single level works fine.
Trying to unstack multiple level does not work as expected.
Looks like when handling multiple levels the unstack are applied consecutively, ok for the first unstack, but following ones should have level adapted internally, which does not seem to happen.
First example tries to unstack level 0 and 1 but level 0 and 2 get unstacked.
Second example, idea is to unstack level 1 and 2 but this gives an error, since after level 1 is unstacked, there is no level 2 any more this became level 1 - see also last example.
The text was updated successfully, but these errors were encountered: