1 Series.cat.as_unordered(*args, **kwargs)
1 import pandas as pd
2
3 ser = pd.Series(['y', 'w', 'x', 'x', 'z'], dtype= 'category')
4
5 print('The original categories object :')
6 print(ser)
7
8 res = ser.cat.as_unordered()
9 print('The ordered categories :')
10 print(res)
1 The original categories object :
2 0 y
3 1 w
4 2 x
5 3 x
6 4 z
7 dtype: category
8 Categories (4, object): ['w', 'x', 'y', 'z']
9 The ordered categories :
10 0 y
11 1 w
12 2 x
13 3 x
14 4 z
15 dtype: category
16 Categories (4, object): ['w', 'x', 'y', 'z']
1 import pandas as pd
2
3 cat = pd.Categorical(['x1', 'x1', 'y1', 'x1', 'z1'])
4
5 print('The original categories object :')
6 print(cat)
7
8 res = cat.as_unordered()
9 print('The ordered categories :')
10 print(res)
1 The original categories object :
2 ['x1', 'x1', 'y1', 'x1', 'z1']
3 Categories (3, object): ['x1', 'y1', 'z1']
4
5 The ordered categories :
6 ['x1', 'x1', 'y1', 'x1', 'z1']
7 Categories (3, object): ['x1', 'y1', 'z1']