Existing function to slice pandas object by axis number

Posted by Zero on Stack Overflow See other posts from Stack Overflow or by Zero
Published on 2014-06-12T03:19:14Z Indexed on 2014/06/12 3:25 UTC
Read the original article Hit count: 109

Filed under:

Pandas has the following indexers:

Object Type    Indexers
Series         s.loc[indexer]
DataFrame      df.loc[row_indexer,column_indexer]
Panel          p.loc[item_indexer,major_indexer,minor_indexer]

I would like to be able to index dynamically by axis, for example:

df = pd.DataFrame(data=0, index=['row1', 'row2', 'row3'], columns=['col1', 'col2', col3'])
df.index(['row1', 'row3'], axis=0)     # index by rows
df.index(['col1', 'col2'], axis=1)     # index by columns

Is there a built-in function that does this?

© Stack Overflow or respective owner

Related posts about pandas