Python 如何将操纵的分类变量编码回原始值?

Python 如何将操纵的分类变量编码回原始值?,python,Python,我的数据框中有一个分类变量。然后,我对它进行编码,以便传递到神经网络中。然而,我的最终可视化图形当然仍然显示了分类变量的编码/数值,我很难将其映射回其原始值打印格式可以是:jpg、png、ico、heic、pdf、word等 我使用此命令首先将分类变量“Print Format”编码为数值: le = preprocessing.LabelEncoder() for x in df.columns: if df[x].dtypes=='object': df[x]=le.f

我的数据框中有一个分类变量。然后,我对它进行编码,以便传递到神经网络中。然而,我的最终可视化图形当然仍然显示了分类变量的编码/数值,我很难将其映射回其原始值
打印格式可以是:jpg、png、ico、heic、pdf、word等

我使用此命令首先将分类变量“Print Format”编码为数值:

le = preprocessing.LabelEncoder()
for x in df.columns:
    if df[x].dtypes=='object':
       df[x]=le.fit_transform(df[x].astype(str))
然后,我想在最终可视化之前使用以下代码将其还原回来:

le = preprocessing.LabelEncoder()
for x in df.columns:
    if df[x].dtypes=='object':
       df[x]=le.inverse_transform(df[x].astype(str))

…但可视化仍不显示原始值。为什么?

只需使用已实现的函数即可

le.inverse_transform(df[x])

这是我在最终可视化之前添加的代码:
le=preprocessing.LabelEncoder(),用于df.columns中的x:if df[x].dtypes=='object':df[x]=le.inverse_transform(df[x].astype(str))
但是可视化仍然没有显示原始值。为什么?有人能帮忙吗?