Existing function to slice pandas object by axis number
- by Zero
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?