I have a dictionary which looks like this: di = {1: \"A\", 2: \"B\"}
di = {1: \"A\", 2: \"B\"}
I would like to apply it to the \"col1\" column of a dataframe similar to:
A nice complete solution that keeps a map of your class labels:
labels = features['col1'].unique() labels_dict = dict(zip(labels, range(len(labels)))) features = features.replace({"col1": labels_dict})
This way, you can at any point refer to the original class label from labels_dict.