How do I make this comparison using the set categorical rules instead of the lexicon order rule?
Given the dataset:
df = pd.DataFrame({
'NUMBER':[12, 26, 16, 34, 38, 1, 26, 8],
'SHIRT_SIZE':['S', 'M', 'XL', 'L', 'S', 'M', 'L', 'XL'],
'SHIRT_SIZE2':['M', 'S', 'L', 'XL', 'M', 'L', 'XL', 'S']
})
from pandas.api.types import CategoricalDtype
c_dtype = CategoricalDtype(categories = ["S","M","L","XL"],ordered = True)
df['SHIRT_SIZE'] = df['SHIRT_SIZE'].astype(c_dtype)
df['SHIRT_SIZE2'] = df['SHIRT_SIZE2'].astype(c_dtype)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…