pandas.CategoricalDtype#
- class pandas.CategoricalDtype(categories=None, ordered=False)[源代码]#
键入类别和顺序的分类数据。
- 参数
- categories序列,可选
必须是唯一的,并且不能包含任何Null。类别存储在索引中,如果提供了索引,则将使用该索引的数据类型。
- orderedBool或None,默认为False
该定语是否被视为有序的定语。当在组合类别的操作(例如astype)中使用时,None可用于维护现有类别的有序值,如果没有要维护的现有有序,则None将解析为False。
参见
Categorical
以经典的R/S+方式表示一个分类变量。
注意事项
此类对于指定
Categorical
与价值无关。看见 CategoricalDtype 想要更多。示例
>>> t = pd.CategoricalDtype(categories=['b', 'a'], ordered=True) >>> pd.Series(['a', 'b', 'a', 'c'], dtype=t) 0 a 1 b 2 a 3 NaN dtype: category Categories (2, object): ['b' < 'a']
可以通过提供空索引来创建具有特定数据类型的空CategoricalDtype。具体如下:
>>> pd.CategoricalDtype(pd.DatetimeIndex([])).categories.dtype dtype('<M8[ns]')
属性
一个
Index
包含允许的唯一类别的。类别是否具有有序关系。
方法:
None