Skip to content
Advertisement

how can I apply label encoding by using a dataframe without using labelencoder etc. in Python?

I have two data frames: first:

JavaScript

enter image description here

second:

JavaScript

enter image description here

I need to do label encoding to the first data frame values by using the second data frame. I tried converting the second data frame to a dictionary and then replacing the first data frame values.

such as;

JavaScript

I couldn’t print the proper dictionary format.

I want to see the output like:

JavaScript

enter image description here

So, How can I replace the first data frame values( X, Y, Z) with second data frame labels?

Advertisement

Answer

here is one way to do it, using melt, and pivot

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement