Vous êtes un professionnel et vous avez besoin d'une formation ?
Programmation Python
Les fondamentaux
Voir le programme détaillé
Module « pandas »
Classe « CategoricalIndex »
Informations générales
Héritage
builtins.object
DirNamesMixin
PandasObject
builtins.object
OpsMixin
IndexOpsMixin
Index
ExtensionIndex
NDArrayBackedExtensionIndex
CategoricalIndex
Définition
class CategoricalIndex(NDArrayBackedExtensionIndex):
help(CategoricalIndex)
Index based on an underlying :class:`Categorical`.
CategoricalIndex, like Categorical, can only take on a limited,
and usually fixed, number of possible values (`categories`). Also,
like Categorical, it might have an order, but numerical operations
(additions, divisions, ...) are not possible.
Parameters
----------
data : array-like (1-dimensional)
The values of the categorical. If `categories` are given, values not in
`categories` will be replaced with NaN.
categories : index-like, optional
The categories for the categorical. Items need to be unique.
If the categories are not given here (and also not in `dtype`), they
will be inferred from the `data`.
ordered : bool, optional
Whether or not this categorical is treated as an ordered
categorical. If not given here or in `dtype`, the resulting
categorical will be unordered.
dtype : CategoricalDtype or "category", optional
If :class:`CategoricalDtype`, cannot be used together with
`categories` or `ordered`.
copy : bool, default False
Make a copy of input ndarray.
name : object, optional
Name to be stored in the index.
Attributes
----------
codes
categories
ordered
Methods
-------
rename_categories
reorder_categories
add_categories
remove_categories
remove_unused_categories
set_categories
as_ordered
as_unordered
map
Raises
------
ValueError
If the categories do not validate.
TypeError
If an explicit ``ordered=True`` is given but no `categories` and the
`values` are not sortable.
See Also
--------
Index : The base pandas Index type.
Categorical : A categorical array.
CategoricalDtype : Type for categorical data.
Notes
-----
See the `user guide
<https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html#categoricalindex>`__
for more.
Examples
--------
>>> pd.CategoricalIndex(["a", "b", "c", "a", "b", "c"])
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'],
categories=['a', 'b', 'c'], ordered=False, dtype='category')
``CategoricalIndex`` can also be instantiated from a ``Categorical``:
>>> c = pd.Categorical(["a", "b", "c", "a", "b", "c"])
>>> pd.CategoricalIndex(c)
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'],
categories=['a', 'b', 'c'], ordered=False, dtype='category')
Ordered ``CategoricalIndex`` can have a min and max value.
>>> ci = pd.CategoricalIndex(
... ["a", "b", "c", "a", "b", "c"], ordered=True, categories=["c", "b", "a"]
... )
>>> ci
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'],
categories=['c', 'b', 'a'], ordered=True, dtype='category')
>>> ci.min()
'c'
Constructeur(s)
Liste des attributs statiques
array | <pandas._libs.properties.CachedProperty object at 0x0000020D9B489680> |
dtype | <pandas._libs.properties.CachedProperty object at 0x0000020D9B47BF80> |
hasnans | <pandas._libs.properties.CachedProperty object at 0x0000020D9B488B40> |
is_unique | <pandas._libs.properties.CachedProperty object at 0x0000020D9B4886C0> |
Attributs statiques hérités de la classe NDArrayBackedExtensionIndex
inferred_type
Liste des propriétés
categories | |
codes | |
empty | |
has_duplicates | |
inferred_type | |
is_monotonic_decreasing | |
is_monotonic_increasing | |
name | |
names | |
nbytes | |
ndim | |
nlevels | |
ordered | |
shape | |
size | |
T | |
values | |
Propriétés héritées de la classe IndexOpsMixin
array, dtype, is_unique
Opérateurs hérités de la classe Index
__getitem__, __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
Méthodes héritées de la classe NDArrayBackedExtensionIndex
__init_subclass__, __subclasshook__
Méthodes héritées de la classe Index
__abs__, __array__, __array_ufunc__, __array_wrap__, __bool__, __copy__, __deepcopy__, __len__, __nonzero__, __reduce__, __repr__, all, any, append, argmax, argmin, argsort, asof, asof_locs, astype, copy, delete, diff, difference, drop, drop_duplicates, droplevel, dropna, duplicated, fillna, format, get_indexer, get_indexer_for, get_indexer_non_unique, get_level_values, get_loc, get_slice_bound, groupby, holds_integer, identical, infer_objects, insert, intersection, is_, is_boolean, is_categorical, is_floating, is_integer, is_interval, is_numeric, is_object, isin, isna, isnull, join, max, memory_usage, min, notna, notnull, putmask, ravel, rename, repeat, round, set_names, shift, slice_indexer, slice_locs, sort, sort_values, sortlevel, symmetric_difference, take, to_flat_index, to_frame, to_series, union, unique, view, 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 ?
Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé
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 :