pandas.MultiIndex¶
- class pandas.MultiIndex¶
A multi-level, or hierarchical, index object for pandas objects
Parameters: levels : sequence of arrays
The unique labels for each level
labels : sequence of arrays
Integers for each level designating which label at each location
sortorder : optional int
Level of sortedness (must be lexicographically sorted by that level)
names : optional sequence of objects
Names for each of the index levels. (name is accepted for compat)
copy : boolean, default False
Copy the meta-data
verify_integrity : boolean, default True
Check that the levels/labels are consistent and valid
Attributes
T return the transpose, which is by definition self asi8 base return the base object if the memory of the underlying data is data return the data pointer of the underlying data dtype dtype_str flags has_duplicates hasnans inferred_type is_all_dates is_monotonic alias for is_monotonic_increasing (deprecated) is_monotonic_decreasing return if the index is monotonic decreasing (only equal or is_monotonic_increasing return if the index is monotonic increasing (only equal or is_unique itemsize return the size of the dtype of the item of the underlying data labels levels levshape lexsort_depth name names Names of levels in MultiIndex nbytes ndim return the number of dimensions of the underlying data, nlevels shape return a tuple of the shape of the underlying data size return the number of elements in the underlying data strides return the strides of the underlying data values Methods
all([other]) any([other]) append(other) Append a collection of Index options together argmax([axis]) return a ndarray of the maximum argument indexer argmin([axis]) return a ndarray of the minimum argument indexer argsort(*args, **kwargs) asof(label) For a sorted index, return the most recent label up to and including the passed label. asof_locs(where, mask) where : array of timestamps astype(dtype) copy([names, dtype, levels, labels, deep, ...]) Make a copy of this object. delete(loc) Make new index with passed location deleted diff(*args, **kwargs) difference(other) Compute sorted set difference of two MultiIndex objects drop(labels[, level, errors]) Make new MultiIndex with passed list of labels deleted drop_duplicates(*args, **kwargs) Return Index with duplicate values removed droplevel([level]) Return Index with requested level removed. duplicated(*args, **kwargs) Return boolean np.array denoting duplicate values equal_levels(other) Return True if the levels of both MultiIndex objects are the same equals(other) Determines if two MultiIndex objects have the same labeling information factorize([sort, na_sentinel]) Encode the object as an enumerated type or categorical variable fillna([value, downcast]) Fill NA/NaN values with the specified value format([space, sparsify, adjoin, names, ...]) from_arrays(arrays[, sortorder, names]) Convert arrays to MultiIndex from_product(iterables[, sortorder, names]) Make a MultiIndex from the cartesian product of multiple iterables from_tuples(tuples[, sortorder, names]) Convert list of tuples to MultiIndex get_duplicates() get_indexer(target[, method, limit, tolerance]) Compute indexer and mask for new index given the current index. get_indexer_for(target, **kwargs) guaranteed return of an indexer even when non-unique get_indexer_non_unique(target) return an indexer suitable for taking from a non unique index get_level_values(level) Return vector of label values for requested level, equal to the length get_loc(key[, method]) Get integer location, slice or boolean mask for requested label or tuple. get_loc_level(key[, level, drop_level]) Get integer location slice for requested label or tuple get_locs(tup) Given a tuple of slices/lists/labels/boolean indexer to a level-wise get_major_bounds([start, end, step, kind]) For an ordered MultiIndex, compute the slice locations for input labels. get_slice_bound(label, side, kind) get_value(series, key) get_values() return the underlying data as an ndarray groupby(to_groupby) Group the index labels by a given array of values. holds_integer() identical(other) Similar to equals, but check that other comparable attributes are insert(loc, item) Make new MultiIndex inserting new item at location intersection(other) Form the intersection of two MultiIndex objects, sorting if possible is_(other) More flexible, faster check like is but that works through views is_boolean() is_categorical() is_floating() is_integer() is_lexsorted() Return True if the labels are lexicographically sorted is_lexsorted_for_tuple(tup) Return True if we are correctly lexsorted given the passed tuple is_mixed() is_numeric() is_object() is_type_compatible(kind) isin(values[, level]) Compute boolean array of whether each index value is found in the passed set of values. item() return the first element of the underlying data as a python join(other[, how, level, return_indexers]) this is an internal non-public method map(mapper) max() The maximum value of the object memory_usage([deep]) Memory usage of my values min() The minimum value of the object nunique([dropna]) Return number of unique elements in the object. order([return_indexer, ascending]) Return sorted copy of Index putmask(mask, value) return a new Index of the values set with the mask ravel([order]) return an ndarray of the flattened values of the underlying data reindex(target[, method, level, limit, ...]) Create index with target’s values (move/add/delete values as necessary) rename(names[, level, inplace]) Set new names on index. reorder_levels(order) Rearrange levels using input order. repeat(n) searchsorted(key[, side]) np.ndarray searchsorted compat set_labels(labels[, level, inplace, ...]) Set new labels on MultiIndex. set_levels(levels[, level, inplace, ...]) Set new levels on MultiIndex. set_names(names[, level, inplace]) Set new names on index. set_value(arr, key, value) Fast lookup of value from 1-dimensional ndarray. shift([periods, freq]) Shift Index containing datetime objects by input number of periods and slice_indexer([start, end, step, kind]) For an ordered Index, compute the slice indexer for input labels and slice_locs([start, end, step, kind]) For an ordered MultiIndex, compute the slice locations for input labels. sort(*args, **kwargs) sort_values([return_indexer, ascending]) Return sorted copy of Index sortlevel([level, ascending, sort_remaining]) Sort MultiIndex at the requested level. str alias of StringMethods summary([name]) swaplevel(i, j) Swap level i with level j. sym_diff(other[, result_name]) Compute the sorted symmetric difference of two Index objects. take(indexer[, axis]) to_datetime([dayfirst]) For an Index containing strings or datetime.datetime objects, attempt to_hierarchical(n_repeat[, n_shuffle]) Return a MultiIndex reshaped to conform to the shapes given by n_repeat and n_shuffle. to_native_types([slicer]) slice and dice then format to_series(**kwargs) Create a Series with both index and values equal to the index keys tolist() return a list of the Index values transpose() return the transpose, which is by definition self truncate([before, after]) Slice index between two labels / tuples, return new MultiIndex union(other) Form the union of two MultiIndex objects, sorting if possible unique() Return array of unique values in the object. value_counts([normalize, sort, ascending, ...]) Returns object containing counts of unique values. view([cls]) this is defined as a copy with the same identity