@@ -1163,6 +1163,17 @@ def add_categories(self, new_categories, inplace=no_default):
1163
1163
remove_categories : Remove the specified categories.
1164
1164
remove_unused_categories : Remove categories which are not used.
1165
1165
set_categories : Set the categories to the specified ones.
1166
+
1167
+ Examples
1168
+ --------
1169
+ >>> c = pd.Categorical(['c', 'b', 'c'])
1170
+ >>> c
1171
+ ['c', 'b', 'c']
1172
+ Categories (2, object): ['b', 'c']
1173
+
1174
+ >>> c.add_categories(['d', 'a'])
1175
+ ['c', 'b', 'c']
1176
+ Categories (4, object): ['b', 'c', 'd', 'a']
1166
1177
"""
1167
1178
if inplace is not no_default :
1168
1179
warn (
@@ -1227,6 +1238,17 @@ def remove_categories(self, removals, inplace=no_default):
1227
1238
add_categories : Add new categories.
1228
1239
remove_unused_categories : Remove categories which are not used.
1229
1240
set_categories : Set the categories to the specified ones.
1241
+
1242
+ Examples
1243
+ --------
1244
+ >>> c = pd.Categorical(['a', 'c', 'b', 'c', 'd'])
1245
+ >>> c
1246
+ ['a', 'c', 'b', 'c', 'd']
1247
+ Categories (4, object): ['a', 'b', 'c', 'd']
1248
+
1249
+ >>> c.remove_categories(['d', 'a'])
1250
+ [NaN, 'c', 'b', 'c', NaN]
1251
+ Categories (2, object): ['b', 'c']
1230
1252
"""
1231
1253
if inplace is not no_default :
1232
1254
warn (
@@ -1286,6 +1308,23 @@ def remove_unused_categories(self, inplace=no_default):
1286
1308
add_categories : Add new categories.
1287
1309
remove_categories : Remove the specified categories.
1288
1310
set_categories : Set the categories to the specified ones.
1311
+
1312
+ Examples
1313
+ --------
1314
+ >>> c = pd.Categorical(['a', 'c', 'b', 'c', 'd'])
1315
+ >>> c
1316
+ ['a', 'c', 'b', 'c', 'd']
1317
+ Categories (4, object): ['a', 'b', 'c', 'd']
1318
+
1319
+ >>> c[2] = 'a'
1320
+ >>> c[4] = 'c'
1321
+ >>> c
1322
+ ['a', 'c', 'a', 'c', 'c']
1323
+ Categories (4, object): ['a', 'b', 'c', 'd']
1324
+
1325
+ >>> c.remove_unused_categories()
1326
+ ['a', 'c', 'a', 'c', 'c']
1327
+ Categories (2, object): ['a', 'c']
1289
1328
"""
1290
1329
if inplace is not no_default :
1291
1330
warn (
0 commit comments