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

set_index with multindex on columns destroys column-multiindex #764

Closed
adamklein opened this issue Feb 8, 2012 · 1 comment
Closed

set_index with multindex on columns destroys column-multiindex #764

adamklein opened this issue Feb 8, 2012 · 1 comment
Labels
Milestone

Comments

@adamklein
Copy link
Contributor

Per Chris Billington on pystatsmodels

In [8]: df
Out[8]: 
          a         b         c  routine1            routine2       top          
                                  result1   result2   result1        OD          
                                                                     wx        wy
0 -0.914239 -0.230830 -0.421134  0.131751 -0.902347  0.382893  0.334615  0.909842
1 -0.533285 -0.878316 -3.046224 -0.760047  0.299502 -0.268321 -0.709366 -0.878868
2  0.804353 -1.203268 -1.221442 -1.948503  0.156240 -0.439375 -0.921254  1.119102

In [9]: df2 = df.set_index([('a','','')])

In [10]: df2
Out[10]: 
<class 'pandas.core.frame.DataFrame'>
Index: 3 entries, -0.914238702285 to 0.804353019197
Data columns:
('b', '', '')                  3  non-null values
('c', '', '')                  3  non-null values
('routine1', 'result1', '')    3  non-null values
('routine1', 'result2', '')    3  non-null values
('routine2', 'result1', '')    3  non-null values
('top', 'OD', 'wx')            3  non-null values
('top', 'OD', 'wy')            3  non-null values
dtypes: float64(7)

In [11]: df2.columns
Out[11]: 
Index([('b', '', ''), ('c', '', ''), ('routine1', 'result1', ''),
       ('routine1', 'result2', ''), ('routine2', 'result1', ''),
       ('top', 'OD', 'wx'), ('top', 'OD', 'wy')], dtype=object)
@adamklein
Copy link
Contributor Author

Code to construct df:

arrays = [[  'a',   'b',   'c',    'top',    'top', 'routine1', 'routine1', 'routine2'],
        [   '',    '',    '',     'OD',     'OD', 'result1',   'result2', 'result1'],
        [   '',    '',    '',     'wx',     'wy',        '',          '',        '']]

tuples = zip(*arrays)
tuples.sort()
index = MultiIndex.from_tuples(tuples)

df = DataFrame(randn(3,8), columns=index)

dan-nadler pushed a commit to dan-nadler/pandas that referenced this issue Sep 23, 2019
Release 1.78 and tick over the next version to 1.79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant