how to use label encoding in python

from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()
companydata.ShelveLoc = le.fit_transform(companydata.ShelveLoc)

Here is what the above code is Doing:
1. Importing the LabelEncoder class from the sklearn library
2. Creating an object of the LabelEncoder class
3. Using the fit_transform method of the LabelEncoder class on the ShelveLoc column of the companydata dataframe.
4. Assigning the result to the ShelveLoc column itself.