用法:
Series.cat()
Series 值的分類屬性的訪問器對象。
請注意,分配給
categories
是就地操作,而所有方法默認返回新的分類數據(但可以使用inplace=True
調用)。- data:係列或分類索引
參數:
例子:
>>> 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']
>>> s.cat.categories Index(['a', 'b', 'c'], dtype='object')
>>> 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']
>>> 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']
>>> 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']
>>> s.cat.remove_categories(["a", "c"]) 0 NaN 1 b 2 b 3 NaN 4 NaN 5 NaN dtype:category Categories (1, object):['b']
>>> 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']
>>> 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']
>>> s.cat.as_ordered() 0 a 1 b 2 b 3 c 4 c 5 c dtype:category Categories (3, object):['a' < 'b' < 'c']
>>> s.cat.as_unordered() 0 a 1 b 2 b 3 c 4 c 5 c dtype:category Categories (3, object):['a', 'b', 'c']
相關用法
- Python pandas.Series.cat.remove_categories用法及代碼示例
- Python pandas.Series.cat.rename_categories用法及代碼示例
- Python pandas.Series.cat.add_categories用法及代碼示例
- Python pandas.Series.cat.remove_unused_categories用法及代碼示例
- Python pandas.Series.combine_first用法及代碼示例
- Python pandas.Series.convert_dtypes用法及代碼示例
- Python pandas.Series.combine用法及代碼示例
- Python pandas.Series.compare用法及代碼示例
- Python pandas.Series.copy用法及代碼示例
- Python pandas.Series.cumsum用法及代碼示例
- Python pandas.Series.cumprod用法及代碼示例
- Python pandas.Series.cov用法及代碼示例
- Python pandas.Series.cummin用法及代碼示例
- Python pandas.Series.cummax用法及代碼示例
- Python pandas.Series.count用法及代碼示例
- Python pandas.Series.clip用法及代碼示例
- Python pandas.Series.corr用法及代碼示例
- Python pandas.Series.add_prefix用法及代碼示例
- Python pandas.Series.map用法及代碼示例
- Python pandas.Series.max用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.cat。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。