Skip to content
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

different view when index a panel with multiindex #15762

Closed
ianzhy opened this issue Mar 21, 2017 · 1 comment
Closed

different view when index a panel with multiindex #15762

ianzhy opened this issue Mar 21, 2017 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex

Comments

@ianzhy
Copy link

ianzhy commented Mar 21, 2017

Code Sample, a copy-pastable example if possible

Problem description

I find a bug when using panel.apply(), and with some digging, I find an interesting indexing problem caused by multiindex in Panel Object. It is demonstrated below:

# 
import pandas as pd
pn1 = pd.Panel(pd.np.random.random(size=(3,4,5)),items=['AAA','BBB','CCC'])
print pn1.loc[:,:,1]
pn2 = pn1.copy()
pn2.major_axis = pd.MultiIndex.from_product([list('AB'),list('ab')])
print pn2.loc[:,:,1]

Output:

        AAA       BBB       CCC
0  0.182982  0.774812  0.894589
1  0.654716  0.695453  0.790078
2  0.340826  0.941283  0.938544
3  0.351851  0.971896  0.362317
            A                   B          
            a         b         a         b
AAA  0.182982  0.654716  0.340826  0.351851
BBB  0.774812  0.695453  0.941283  0.971896
CCC  0.894589  0.790078  0.938544  0.362317

With a multiindex as the major_axis of Panel object, the indexing result is transposed. And because of that, when using pn.apply(func, axis=('items','major')), it give you the wrong results when the major_axis is a multiindex.
Is this a bug? if not, then what is the purpose that it is designed like this?
Thanks for help.

@jreback
Copy link
Contributor

jreback commented Mar 21, 2017

duplicate of #6286

Panel is being deprecated, mainly because of the difficulties of indexing :>
see #13563

for multi-dimensional data would recommend a DataFrame with a multi-index or use https://github.com/pydata/xarray

@jreback jreback closed this as completed Mar 21, 2017
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Panel Duplicate Report Duplicate issue or pull request labels Mar 21, 2017
@jreback jreback added this to the No action milestone Mar 21, 2017
@jreback jreback modified the milestones: No action, won't fix Jul 11, 2017
@TomAugspurger TomAugspurger modified the milestones: won't fix, No action Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
Development

No branches or pull requests

3 participants