Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.cat.categories#

Series.cat.categories[source]#

The categories of this categorical.

Setting assigns new values to each category (effectively a rename ofeach individual category).

The assigned value has to be a list-like object. All items must beunique and the number of items in the new categories must be the sameas the number of items in the old categories.

Raises:
ValueError

If the new categories do not validate as categories or if thenumber of new categories is unequal the number of old categories

See also

rename_categories

Rename categories.

reorder_categories

Reorder categories.

add_categories

Add new categories.

remove_categories

Remove the specified categories.

remove_unused_categories

Remove categories which are not used.

set_categories

Set the categories to the specified ones.

Examples

Forpandas.Series:

>>>ser=pd.Series(['a','b','c','a'],dtype='category')>>>ser.cat.categoriesIndex(['a', 'b', 'c'], dtype='object')
>>>raw_cat=pd.Categorical(['a','b','c','a'],categories=['b','c','d'])>>>ser=pd.Series(raw_cat)>>>ser.cat.categoriesIndex(['b', 'c', 'd'], dtype='object')

Forpandas.Categorical:

>>>cat=pd.Categorical(['a','b'],ordered=True)>>>cat.categoriesIndex(['a', 'b'], dtype='object')

Forpandas.CategoricalIndex:

>>>ci=pd.CategoricalIndex(['a','c','b','a','c','b'])>>>ci.categoriesIndex(['a', 'b', 'c'], dtype='object')
>>>ci=pd.CategoricalIndex(['a','c'],categories=['c','b','a'])>>>ci.categoriesIndex(['c', 'b', 'a'], dtype='object')

[8]ページ先頭

©2009-2025 Movatter.jp