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.
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,
index_stack_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 name_dict.
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.
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().
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.
Method generated by attrs for class ExceptLevel.
value class variable¶
One or more level positions or names.