Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les fondamentaux
Voir le programme détaillé
Module « pandas »

Classe « MultiIndex »

Informations générales

Héritage

builtins.object
    DirNamesMixin
        PandasObject
builtins.object
    OpsMixin
        IndexOpsMixin
            Index
                MultiIndex

Définition

class MultiIndex(Index):

help(MultiIndex)

A multi-level, or hierarchical, index object for pandas objects.

Parameters
----------
levels : sequence of arrays
    The unique labels for each level.
codes : 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 : bool, default False
    Copy the meta-data.
verify_integrity : bool, default True
    Check that the levels/codes are consistent and valid.

Attributes
----------
names
levels
codes
nlevels
levshape
dtypes

Methods
-------
from_arrays
from_tuples
from_product
from_frame
set_levels
set_codes
to_frame
to_flat_index
sortlevel
droplevel
swaplevel
reorder_levels
remove_unused_levels
get_level_values
get_indexer
get_loc
get_locs
get_loc_level
drop

See Also
--------
MultiIndex.from_arrays  : Convert list of arrays to MultiIndex.
MultiIndex.from_product : Create a MultiIndex from the cartesian product
                          of iterables.
MultiIndex.from_tuples  : Convert list of tuples to a MultiIndex.
MultiIndex.from_frame   : Make a MultiIndex from a DataFrame.
Index : The base pandas Index type.

Notes
-----
See the `user guide
<https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html>`__
for more.

Examples
--------
A new ``MultiIndex`` is typically constructed using one of the helper
methods :meth:`MultiIndex.from_arrays`, :meth:`MultiIndex.from_product`
and :meth:`MultiIndex.from_tuples`. For example (using ``.from_arrays``):

>>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
>>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color'))
MultiIndex([(1,  'red'),
            (1, 'blue'),
            (2,  'red'),
            (2, 'blue')],
           names=['number', 'color'])

See further examples for how to construct a MultiIndex in the doc strings
of the mentioned helper methods.

Constructeur(s)

Signature du constructeur Description
__new__(cls, levels=None, codes=None, sortorder=None, names=None, dtype=None, copy: 'bool' = False, name=None, verify_integrity: 'bool' = True) -> 'Self'
__init__(self, /, *args, **kwargs) Initialize self. See help(type(self)) for accurate signature. [extrait de __init__.__doc__]

Liste des attributs statiques

Nom de l'attribut Valeur
dtype<pandas._libs.properties.CachedProperty object at 0x0000020D9B4F8E40>
dtypes<pandas._libs.properties.CachedProperty object at 0x0000020D9B4F8A80>
hasnans<pandas._libs.properties.CachedProperty object at 0x0000020D9B488B40>
inferred_type<pandas._libs.properties.CachedProperty object at 0x0000020D9B4F8FC0>
is_monotonic_decreasing<pandas._libs.properties.CachedProperty object at 0x0000020D9B4F9040>
is_monotonic_increasing<pandas._libs.properties.CachedProperty object at 0x0000020D9B4F9000>
is_unique<pandas._libs.properties.CachedProperty object at 0x0000020D9B4886C0>
levels<pandas._libs.properties.CachedProperty object at 0x0000020D9B4F8AC0>
nbytes<pandas._libs.properties.CachedProperty object at 0x0000020D9B4F8EC0>

Attributs statiques hérités de la classe Index

array

Liste des propriétés

Nom de la propriétéDescription
array
codes
empty
has_duplicates
levshape
name
names
ndim
nlevels
shape
size
T
values

Propriétés héritées de la classe Index

is_monotonic_decreasing, is_monotonic_increasing, nbytes

Propriétés héritées de la classe IndexOpsMixin

dtype, is_unique

Liste des opérateurs

Signature de l'opérateur Description
__contains__(self, key: 'Any') -> 'bool'
__getitem__(self, key)

Opérateurs hérités de la classe Index

__iadd__, __invert__, __neg__, __pos__, __setitem__

Opérateurs hérités de la classe OpsMixin

__add__, __and__, __eq__, __floordiv__, __ge__, __gt__, __le__, __lt__, __mod__, __mul__, __ne__, __or__, __pow__, __radd__, __rand__, __rfloordiv__, __rmod__, __rmul__, __ror__, __rpow__, __rsub__, __rtruediv__, __rxor__, __sub__, __truediv__, __xor__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__array__(self, dtype=None, copy=None) -> 'np.ndarray' the array interface, return my values [extrait de __array__.__doc__]
__len__(self) -> 'int'
__reduce__(self) Necessary for making this object picklable [extrait de __reduce__.__doc__]
append(self, other)
argsort(self, *args, na_position: 'str' = 'last', **kwargs) -> 'npt.NDArray[np.intp]'
astype(self, dtype, copy: 'bool' = True)
copy(self, names=None, deep: 'bool' = False, name=None) -> 'Self'
delete(self, loc) -> 'MultiIndex'
drop(self, codes, level: 'Index | np.ndarray | Iterable[Hashable] | None' = None, errors: 'IgnoreRaise' = 'raise') -> 'MultiIndex'
dropna(self, how: 'AnyAll' = 'any') -> 'MultiIndex'
duplicated(self, keep: 'DropKeep' = 'first') -> 'npt.NDArray[np.bool_]'
equal_levels(self, other: 'MultiIndex') -> 'bool'
equals(self, other: 'object') -> 'bool'
fillna(self, value=None, downcast=None)
format(self, name: 'bool | None' = None, formatter: 'Callable | None' = None, na_rep: 'str | None' = None, names: 'bool' = False, space: 'int' = 2, sparsify=None, adjoin: 'bool' = True) -> 'list'
from_arrays(arrays, sortorder: 'int | None' = None, names: 'Sequence[Hashable] | Hashable | lib.NoDefault' = <no_default>) -> 'MultiIndex'
from_frame(df: 'DataFrame', sortorder: 'int | None' = None, names: 'Sequence[Hashable] | Hashable | None' = None) -> 'MultiIndex'
from_product(iterables: 'Sequence[Iterable[Hashable]]', sortorder: 'int | None' = None, names: 'Sequence[Hashable] | Hashable | lib.NoDefault' = <no_default>) -> 'MultiIndex'
from_tuples(tuples: 'Iterable[tuple[Hashable, ...]]', sortorder: 'int | None' = None, names: 'Sequence[Hashable] | Hashable | None' = None) -> 'MultiIndex'
get_level_values(self, level) -> 'Index'
get_loc(self, key)
get_loc_level(self, key, level: 'IndexLabel' = 0, drop_level: 'bool' = True)
get_locs(self, seq) -> 'npt.NDArray[np.intp]'
get_slice_bound(self, label: 'Hashable | Sequence[Hashable]', side: "Literal['left', 'right']") -> 'int'
insert(self, loc: 'int', item) -> 'MultiIndex'
isin(self, values, level=None) -> 'npt.NDArray[np.bool_]'
memory_usage(self, deep: 'bool' = False) -> 'int'
putmask(self, mask, value: 'MultiIndex') -> 'MultiIndex'
remove_unused_levels(self) -> 'MultiIndex'
reorder_levels(self, order) -> 'MultiIndex'
repeat(self, repeats: 'int', axis=None) -> 'MultiIndex'
set_codes(self, codes, *, level=None, verify_integrity: 'bool' = True) -> 'MultiIndex'
set_levels(self, levels, *, level=None, verify_integrity: 'bool' = True) -> 'MultiIndex'
slice_locs(self, start=None, end=None, step=None) -> 'tuple[int, int]'
sortlevel(self, level: 'IndexLabel' = 0, ascending: 'bool | list[bool]' = True, sort_remaining: 'bool' = True, na_position: 'str' = 'first') -> 'tuple[MultiIndex, npt.NDArray[np.intp]]'
swaplevel(self, i=-2, j=-1) -> 'MultiIndex'
take(self: 'MultiIndex', indices, axis: 'Axis' = 0, allow_fill: 'bool' = True, fill_value=None, **kwargs) -> 'MultiIndex'
to_flat_index(self) -> 'Index'
to_frame(self, index: 'bool' = True, name=<no_default>, allow_duplicates: 'bool' = False) -> 'DataFrame'
truncate(self, before=None, after=None) -> 'MultiIndex'
unique(self, level=None)
view(self, cls=None) -> 'Self' this is defined as a copy with the same identity [extrait de view.__doc__]

Méthodes héritées de la classe Index

__abs__, __array_ufunc__, __array_wrap__, __bool__, __copy__, __deepcopy__, __init_subclass__, __nonzero__, __repr__, __subclasshook__, all, any, argmax, argmin, asof, asof_locs, diff, difference, drop_duplicates, droplevel, get_indexer, get_indexer_for, get_indexer_non_unique, groupby, holds_integer, identical, infer_objects, intersection, is_, is_boolean, is_categorical, is_floating, is_integer, is_interval, is_numeric, is_object, isna, isnull, join, map, max, min, notna, notnull, ravel, reindex, rename, round, set_names, shift, slice_indexer, sort, sort_values, symmetric_difference, to_series, union, where

Méthodes héritées de la classe PandasObject

__sizeof__

Méthodes héritées de la classe DirNamesMixin

__dir__

Méthodes héritées de la classe IndexOpsMixin

__iter__, factorize, item, nunique, searchsorted, to_list, to_numpy, tolist, transpose, value_counts

Méthodes héritées de la classe OpsMixin

__divmod__, __rdivmod__

Méthodes héritées de la classe object

__delattr__, __format__, __getattribute__, __getstate__, __hash__, __reduce_ex__, __setattr__, __str__

Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé