Truth.reorder_levels#
missionbio.demultiplex.dna.truth.Truth.reorder_levels
- Truth.reorder_levels(order: Sequence[Union[str, int]], axis: Union[str, int] = 0) DataFrame #
Rearrange index levels using input order. May not drop or duplicate levels.
- Parameters:
- orderlist of int or list of str
List representing new level order. Reference level by number (position) or by key (label).
- axis{0 or ‘index’, 1 or ‘columns’}, default 0
Where to reorder levels.
- Returns:
- DataFrame
Examples
>>> data = { ... "class": ["Mammals", "Mammals", "Reptiles"], ... "diet": ["Omnivore", "Carnivore", "Carnivore"], ... "species": ["Humans", "Dogs", "Snakes"], ... } >>> df = pd.DataFrame(data, columns=["class", "diet", "species"]) >>> df = df.set_index(["class", "diet"]) >>> df species class diet Mammals Omnivore Humans Carnivore Dogs Reptiles Carnivore Snakes
Let’s reorder the levels of the index:
>>> df.reorder_levels(["diet", "class"]) species diet class Omnivore Mammals Humans Carnivore Mammals Dogs Reptiles Snakes
< Class Truth