Here is a small data frame that contains a very small slice of data that I need to encode. DataFrame to Encode
My current effort in doing this is using SciKit-Learns LabelEncoder(),
le = preprocessing.LabelEncoder()
le.fit(["local", "animals", "local", "diet", "food", "health", "local", "police brutality", "police", "kids", "dogs"])
list(le.classes_)
(output)
['animals',
'diet',
'dogs',
'food',
'health',
'kids',
'local',
'police',
'police brutality']
I have now added all my desired targets to the encoder, so now I need to start encoding. The problem is the LabelEncoder takes arguments like this.
le.transform(["local"]) #For the first row in the data frame
(output) array([6])
Now thats the correct encoding for the first row, but how would I do this for every other row? I don't think writing it by hand is very doable as my actual data set is about 6000 samples.
I'm also not sure if the targets should be comma separated or not, I can always change that, but my end goal is to get a new data frame with encoded labels instead of the categorial labels.
Also, since the encoder returns a single array, if I were to do the same things for every row, each with a different amount of labels (i.e (dogs, animals) instead of (local)), I would need to append every array to make a matrix, but that is also something I have no clue how I should do. Thanks so much for the help!