pandas 1.4.2

Parameters

Be aware that assigning to :None:None:`categories` is a inplace operation, while all methods return new categorical data per default (but can be called with :None:None:`inplace=True`).

Parameters

data : Series or CategoricalIndex

Accessor object for categorical properties of the Series values.

Examples

This example is valid syntax, but we were not able to check execution
>>> s = pd.Series(list("abbccc")).astype("category")
... s 0 a 1 b 2 b 3 c 4 c 5 c dtype: category Categories (3, object): ['a', 'b', 'c']
This example is valid syntax, but we were not able to check execution
>>> s.cat.categories
Index(['a', 'b', 'c'], dtype='object')
This example is valid syntax, but we were not able to check execution
>>> s.cat.rename_categories(list("cba"))
0    c
1    b
2    b
3    a
4    a
5    a
dtype: category
Categories (3, object): ['c', 'b', 'a']
This example is valid syntax, but we were not able to check execution
>>> s.cat.reorder_categories(list("cba"))
0    a
1    b
2    b
3    c
4    c
5    c
dtype: category
Categories (3, object): ['c', 'b', 'a']
This example is valid syntax, but we were not able to check execution
>>> s.cat.add_categories(["d", "e"])
0    a
1    b
2    b
3    c
4    c
5    c
dtype: category
Categories (5, object): ['a', 'b', 'c', 'd', 'e']
This example is valid syntax, but we were not able to check execution
>>> s.cat.remove_categories(["a", "c"])
0    NaN
1      b
2      b
3    NaN
4    NaN
5    NaN
dtype: category
Categories (1, object): ['b']
This example is valid syntax, but we were not able to check execution
>>> s1 = s.cat.add_categories(["d", "e"])
... s1.cat.remove_unused_categories() 0 a 1 b 2 b 3 c 4 c 5 c dtype: category Categories (3, object): ['a', 'b', 'c']
This example is valid syntax, but we were not able to check execution
>>> s.cat.set_categories(list("abcde"))
0    a
1    b
2    b
3    c
4    c
5    c
dtype: category
Categories (5, object): ['a', 'b', 'c', 'd', 'e']
This example is valid syntax, but we were not able to check execution
>>> s.cat.as_ordered()
0    a
1    b
2    b
3    c
4    c
5    c
dtype: category
Categories (3, object): ['a' < 'b' < 'c']
This example is valid syntax, but we were not able to check execution
>>> s.cat.as_unordered()
0    a
1    b
2    b
3    c
4    c
5    c
dtype: category
Categories (3, object): ['a', 'b', 'c']
See :

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#2589
type: <class 'type'>
Commit: