如何将多列解码为字符串类型(返回原始类型)

2024-09-30 20:29:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样的数据:

我想根据这些数据预测计数列。 但首先,我已经使用LabelEncoder对其进行了编码

我用来编码这些数据的代码是:

def dummyEncode(df)
Hasil = []
columnsToEncode = list(Hasilatribut)
le = LabelEncoder()
for feature in columnsToEncode:
    try:
        df[feature] : le.fit_transform(df[feature]).astype(float)
    except:
            print('Error encoding '+feature)
return df

我的编码结果是:enter image description here

在预测的最后一步,我想将“date”、“tablename”和“attributename”转换为原始类型。 我已经使用了逆_变换,但仍然得到错误

我也尝试这样做: enter image description here

结果仍然类似于“hasil”输出

请帮我解决这个问题


Tags: 数据代码le编码dffordeffeature