A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pandas.pydata.org/docs/dev/user_guide/../reference/api/pandas.CategoricalDtype.html below:

pandas.CategoricalDtype — pandas 3.0.0.dev0+2231.g4f2aa4d2be documentation

pandas.CategoricalDtype#
class pandas.CategoricalDtype(categories=None, ordered=False)[source]#

Type for categorical data with the categories and orderedness.

It is a dtype representation for categorical data, which allows users to define a fixed set of values and optionally impose an ordering. This is particularly useful for handling categorical variables efficiently, as it can significantly reduce memory usage compared to using object dtypes.

Parameters:
categoriessequence, optional

Must be unique, and must not contain any nulls. The categories are stored in an Index, and if an index is provided the dtype of that index will be used.

orderedbool or None, default False

Whether or not this categorical is treated as a ordered categorical. None can be used to maintain the ordered value of existing categoricals when used in operations that combine categoricals, e.g. astype, and will resolve to False if there is no existing ordered to maintain.

Attributes

Methods

See also

Categorical

Represent a categorical variable in classic R / S-plus fashion.

Notes

This class is useful for specifying the type of a Categorical independent of the values. See CategoricalDtype for more.

Examples

>>> 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']

An empty CategoricalDtype with a specific dtype can be created by providing an empty index. As follows,

>>> pd.CategoricalDtype(pd.DatetimeIndex([])).categories.dtype
dtype('<M8[s]')

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4