diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6ca8f6731bbb8..d1e9f103477cc 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5279,7 +5279,9 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs): Convert to ordered categorical type with custom ordering: - >>> ser.astype('category', ordered=True, categories=[2, 1]) + >>> cat_dtype = pd.api.types.CategoricalDtype( + ... categories=[2, 1], ordered=True) + >>> ser.astype(cat_dtype) 0 1 1 2 dtype: category