用法:
class pandas.CategoricalDtype(categories=None, ordered=False)
鍵入具有類別和順序的分類數據。
- categories:順序,可選
必須是唯一的,並且不能包含任何空值。類別存儲在索引中,如果提供了索引,則將使用該索引的 dtype。
- ordered:布爾或無,默認為 False
此分類是否被視為有序分類。在組合分類的操作中使用時,無可用於維護現有分類的有序值,例如astype,如果沒有現有的要維護的命令,則將解析為 False。
參數:
注意:
此類對於指定獨立於值的
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']
可以通過提供空索引來創建具有特定 dtype 的空 CategoricalDtype。如下,
>>> pd.CategoricalDtype(pd.DatetimeIndex([])).categories.dtype dtype('<M8[ns]')
相關用法
- Python pandas.CategoricalIndex.add_categories用法及代碼示例
- Python pandas.CategoricalIndex.remove_unused_categories用法及代碼示例
- Python pandas.CategoricalIndex.remove_categories用法及代碼示例
- Python pandas.CategoricalIndex.map用法及代碼示例
- Python pandas.CategoricalIndex.rename_categories用法及代碼示例
- Python pandas.Categorical用法及代碼示例
- Python pandas.Categorical.from_codes用法及代碼示例
- Python pandas.CategoricalIndex用法及代碼示例
- Python pandas.arrays.IntervalArray.is_empty用法及代碼示例
- Python pandas.DataFrame.ewm用法及代碼示例
- Python pandas.api.types.is_timedelta64_ns_dtype用法及代碼示例
- Python pandas.DataFrame.dot用法及代碼示例
- Python pandas.DataFrame.apply用法及代碼示例
- Python pandas.DataFrame.combine_first用法及代碼示例
- Python pandas.read_pickle用法及代碼示例
- Python pandas.Index.value_counts用法及代碼示例
- Python pandas.DatetimeTZDtype用法及代碼示例
- Python pandas.DataFrame.cumsum用法及代碼示例
- Python pandas.Interval.is_empty用法及代碼示例
- Python pandas.api.indexers.FixedForwardWindowIndexer用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.CategoricalDtype。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。