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
Partial selection using .xs() & .ix[] on a subset of index levels returns a df with the fixed/selected levels dropped (a very nice feature). However, when you partially select using a tuple on all levels you get a data frame with all indices (levels) returned. It would be nice to have an option to return any/all indices when sub-selecting using subset of levels so there is consistency when you reach the lowest index level.
Perhaps there could be a "drop_fixed_index" parameter option when sub-selecting.
In [1]: importnumpyasnpIn [2]: importpandasaspdIn [3]: printpd.__version__0.11.0.dev-80945b6In [4]: # Generate Test DataFrame
...: NUM_ROWS=100000
...:
In [5]: NUM_COLS=10In [6]: col_names= ['A'+numfornuminmap(str,np.arange(NUM_COLS).tolist())]
In [7]: index_cols=col_names[:5]
In [8]: # Set DataFrame to have 5 level Hierarchical Index & Sort Index!
...: # The dtype does not matter try str or np.int64 same results.
...: df=pd.DataFrame(np.random.randint(5, size=(NUM_ROWS,NUM_COLS)), dtype=np.int64, columns=col_names)
...:
In [9]: df=df.set_index(index_cols).sort_index()
...
In [79]: dfOut[79]: <class'pandas.core.frame.DataFrame'>MultiIndex: 100000entries, (0, 0, 0, 0, 0) to (4, 4, 4, 4, 4)
Datacolumns:
A5100000non-nullvaluesA6100000non-nullvaluesA7100000non-nullvaluesA8100000non-nullvaluesA9100000non-nullvaluesdtypes: int64(5)
In [80]: df.ix[(0)]
Out[80]: <class'pandas.core.frame.DataFrame'>MultiIndex: 20011entries, (0, 0, 0, 0) to (4, 4, 4, 4)
Datacolumns:
A520011non-nullvaluesA620011non-nullvaluesA720011non-nullvaluesA820011non-nullvaluesA920011non-nullvaluesdtypes: int64(5)
In [81]: df.ix[(0,1)]
Out[81]: <class'pandas.core.frame.DataFrame'>MultiIndex: 4007entries, (0, 0, 0) to (4, 4, 4)
Datacolumns:
A54007non-nullvaluesA64007non-nullvaluesA74007non-nullvaluesA84007non-nullvaluesA94007non-nullvaluesdtypes: int64(5)
In [82]: df.ix[(0,1,2)]
Out[82]: <class'pandas.core.frame.DataFrame'>MultiIndex: 817entries, (0, 0) to (4, 4)
Datacolumns:
A5817non-nullvaluesA6817non-nullvaluesA7817non-nullvaluesA8817non-nullvaluesA9817non-nullvaluesdtypes: int64(5)
In [83]: df.ix[(0,1,2,3)]
Out[83]: <class'pandas.core.frame.DataFrame'>Int64Index: 162entries, 0to4Datacolumns:
A5162non-nullvaluesA6162non-nullvaluesA7162non-nullvaluesA8162non-nullvaluesA9162non-nullvaluesdtypes: int64(5)
In [84]: df.ix[(0,1,2,3,4)]
Out[84]: A5A6A7A8A9A0A1A2A3A40123412242414410421413424211411214400211420031422331430341411001421024434123404310441412413433401131422203400140410142414220442031421232442014414114410124423013421333412042430440444230400132440003420342433302442201421340In [86]: df.index.lexsort_depthOut[86]: 5
The text was updated successfully, but these errors were encountered:
Partial selection using .xs() & .ix[] on a subset of index levels returns a df with the fixed/selected levels dropped (a very nice feature). However, when you partially select using a tuple on all levels you get a data frame with all indices (levels) returned. It would be nice to have an option to return any/all indices when sub-selecting using subset of levels so there is consistency when you reach the lowest index level.
Perhaps there could be a "drop_fixed_index" parameter option when sub-selecting.
The text was updated successfully, but these errors were encountered: