from sklearn.preprocessing import OrdinalEncoder
import random
import pandas as pd
# the categorical values in the right order
satisfaction = ['Poor', 'Moderate', 'Good', 'Very Good']
# create the mapping list
mapping = [satisfaction]
# create some random data but reproducible data
random.seed(42)
X = pd.DataFrame({'satisfaction': [random.choice(satisfaction) for _ in range(25)]})
print(X)
您可以使用^{} 并提供自己的映射表。映射表的格式是一个列表列表,其中第n个列表包含输入数据第n列中的值
相关问题 更多 >
编程相关推荐