pandas 1.4.2

ParametersRaisesReturnsBackRef
remove_categories(self, removals, inplace=<no_default>)

:None:None:`removals` must be included in the old categories. Values which were in the removed categories will be set to NaN

Parameters

removals : category or list of categories

The categories which should be removed.

inplace : bool, default False

Whether or not to remove the categories inplace or return a copy of this categorical with removed categories.

deprecated

Raises

ValueError

If the removals are not contained in the categories

Returns

cat : Categorical or None

Categorical with removed categories or None if inplace=True .

Remove the specified categories.

See Also

add_categories

Add new categories.

remove_unused_categories

Remove categories which are not used.

rename_categories

Rename categories.

reorder_categories

Reorder categories.

set_categories

Set the categories to the specified ones.

Examples

This example is valid syntax, but we were not able to check execution
>>> c = pd.Categorical(['a', 'c', 'b', 'c', 'd'])
... c ['a', 'c', 'b', 'c', 'd'] Categories (4, object): ['a', 'b', 'c', 'd']
This example is valid syntax, but we were not able to check execution
>>> c.remove_categories(['d', 'a'])
[NaN, 'c', 'b', 'c', NaN]
Categories (2, object): ['b', 'c']
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.arrays.categorical.Categorical.set_categories pandas.core.arrays.categorical.Categorical.add_categories pandas.core.arrays.categorical.Categorical.rename_categories pandas.core.arrays.categorical.Categorical.remove_unused_categories pandas.core.arrays.categorical.Categorical.reorder_categories

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/arrays/categorical.py#1210
type: <class 'function'>
Commit: