Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.cat#

Series.cat()[source]#

Accessor object for categorical properties of the Series values.

Parameters:
dataSeries or CategoricalIndex

Examples

>>>s=pd.Series(list("abbccc")).astype("category")>>>s0    a1    b2    b3    c4    c5    cdtype: categoryCategories (3, object): ['a', 'b', 'c']
>>>s.cat.categoriesIndex(['a', 'b', 'c'], dtype='object')
>>>s.cat.rename_categories(list("cba"))0    c1    b2    b3    a4    a5    adtype: categoryCategories (3, object): ['c', 'b', 'a']
>>>s.cat.reorder_categories(list("cba"))0    a1    b2    b3    c4    c5    cdtype: categoryCategories (3, object): ['c', 'b', 'a']
>>>s.cat.add_categories(["d","e"])0    a1    b2    b3    c4    c5    cdtype: categoryCategories (5, object): ['a', 'b', 'c', 'd', 'e']
>>>s.cat.remove_categories(["a","c"])0    NaN1      b2      b3    NaN4    NaN5    NaNdtype: categoryCategories (1, object): ['b']
>>>s1=s.cat.add_categories(["d","e"])>>>s1.cat.remove_unused_categories()0    a1    b2    b3    c4    c5    cdtype: categoryCategories (3, object): ['a', 'b', 'c']
>>>s.cat.set_categories(list("abcde"))0    a1    b2    b3    c4    c5    cdtype: categoryCategories (5, object): ['a', 'b', 'c', 'd', 'e']
>>>s.cat.as_ordered()0    a1    b2    b3    c4    c5    cdtype: categoryCategories (3, object): ['a' < 'b' < 'c']
>>>s.cat.as_unordered()0    a1    b2    b3    c4    c5    cdtype: categoryCategories (3, object): ['a', 'b', 'c']

[8]ページ先頭

©2009-2025 Movatter.jp