I am converting strings to categorical values in my dataset using the following piece of code.
data[\'weekday\'] = pd.Categorical.from_array(data.weekday).labels
You can create additional dictionary with mapping:
from sklearn import preprocessing le = preprocessing.LabelEncoder() le.fit(data['name']) le_name_mapping = dict(zip(le.classes_, le.transform(le.classes_))) print(le_name_mapping) {'Tom': 0, 'Nick': 1, 'Kate': 2}