indexes module¶
Functions for working with indexes: index and columns.
They perform operations on index objects, such as stacking, combining, and cleansing MultiIndex levels.
Note
"Index" in pandas context is referred to both index and columns.
align_arr_indices_nb function¶
Return indices required to align a to b.
align_index_to function¶
Align index1 to have the same shape as index2 if they have any levels in common.
Returns index slice for the aligning.
align_indexes function¶
Align multiple indexes to each other with align_index_to().
block_index_product_nb function¶
Return indices required for building a block-wise Cartesian product of two factorized indexes.
clean_index function¶
Clean index.
Set drop_duplicates to True to remove duplicate levels.
For details on keep, see drop_duplicate_levels().
Set drop_redundant to True to use drop_redundant_levels().
combine_index_with_keys function¶
Build keys based on index lengths.
combine_indexes function¶
Combine each index in indexes using Cartesian product.
Keyword arguments will be passed to stack_indexes().
concat_indexes function¶
concat_indexes(
*indexes,
index_concat_method='append',
keys=None,
clean_index_kwargs=None,
verify_integrity=True,
axis=1
)
Concatenate indexes.
The following index concatenation methods are supported:
- 'append': append one index to another
- 'union': build a union of indexes
- 'pd_concat': convert indexes to Pandas Series or DataFrames and use
pd.concat - 'factorize': factorize the concatenated index
- 'factorize_each': factorize each index and concatenate while keeping numbers unique
- 'reset': reset the concatenated index without applying
keys - Callable: a custom callable that takes the indexes and returns the concatenated index
Argument index_concat_method also accepts a tuple of two options: the second option gets applied if the first one fails.
Use keys as an index with the same number of elements as there are indexes to add another index level on top of the concatenated indexes.
If verify_integrity is True and keys is None, performs various checks depending on the axis.
cross_index_with function¶
Build a Cartesian product of one index with another while taking into account levels they have in common.
Returns index slices for the aligning.
cross_indexes function¶
Cross multiple indexes with cross_index_with().
drop_duplicate_levels function¶
Drop levels in index with the same name and values.
Set keep to 'last' to keep last levels, otherwise 'first'.
Set keep to None to use the default.
drop_levels function¶
Drop levels in index by their name(s)/position(s).
Provide levels as an instance of ExceptLevel to drop everything apart from the specified levels.
drop_redundant_levels function¶
Drop levels in index that either have a single unnamed value or a range from 0 to n.
find_first_occurrence function¶
Return index of the first occurrence in index.
get_index function¶
Get index of arg by axis.
index_from_values function¶
Create a new pd.Index with name by parsing an iterable values.
Each in values will correspond to an element in the new index.
pick_levels function¶
Pick optional and required levels and return their indices.
Raises an exception if index has less or more levels than expected.
rename_levels function¶
Rename levels in index by mapper.
Mapper can be a single or multiple levels to rename to, or a dictionary that maps old level names to new level names.
repeat_index function¶
Repeat each element in index n times.
Set ignore_ranges to True to ignore indexes of type pd.RangeIndex.
select_levels function¶
Build a new index by selecting one or multiple levels from index.
Provide levels as an instance of ExceptLevel to select everything apart from the specified levels.
stack_indexes function¶
Stack each index in indexes on top of each other, from top to bottom.
tile_index function¶
Tile the whole index n times.
Set ignore_ranges to True to ignore indexes of type pd.RangeIndex.
to_any_index function¶
Convert any index-like object to an index.
Index objects are kept as-is.
ExceptLevel class¶
Class for grouping except one or more levels.
Superclasses
Inherited members
- DefineMixin.asdict()
- DefineMixin.assert_field_not_missing()
- DefineMixin.get_field()
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing()
- DefineMixin.is_field_optional()
- DefineMixin.is_field_required()
- DefineMixin.merge_over()
- DefineMixin.merge_with()
- DefineMixin.replace()
- DefineMixin.resolve()
- DefineMixin.resolve_field()
- Hashable.get_hash()
value class variable¶
One or more level positions or names.
IndexApplier class¶
Abstract class that can apply a function on an index.
Subclasses
add_levels method¶
IndexApplier.add_levels(
*indexes,
on_top=True,
drop_duplicates=None,
keep=None,
drop_redundant=None,
**kwargs
)
Append or prepend levels using stack_indexes().
Set on_top to False to stack at bottom.
See IndexApplier.apply_to_index() for other keyword arguments.
apply_to_index method¶
Apply function apply_func on the index of the instance and return a new instance.
drop_duplicate_levels method¶
Drop any duplicate levels using drop_duplicate_levels().
See IndexApplier.apply_to_index() for other keyword arguments.
drop_levels method¶
Drop levels using drop_levels().
See IndexApplier.apply_to_index() for other keyword arguments.
drop_redundant_levels method¶
Drop any redundant levels using drop_redundant_levels().
See IndexApplier.apply_to_index() for other keyword arguments.
rename_levels method¶
Rename levels using rename_levels().
See IndexApplier.apply_to_index() for other keyword arguments.
select_levels method¶
Select levels using select_levels().
See IndexApplier.apply_to_index() for other keyword arguments.