title: How to label categorical variables in Pandas in order?
body: <p>I have a pandas dataframe with the following categorical variables as columns on the left, and their specific realizations on the right,</p>
  
  <p><a href="https://i.stack.imgur.com/Ucsrlm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ucsrlm.png" alt="enter image description here"></a></p>
  
  <p>(apologies for low-res).</p>
  
  <p>For a statistical regression, I want to label all of these categorical variables, so, for example, in <code>LotShape</code>, <code>Reg</code> becomes <code>0</code>, <code>IR1</code> becomes <code>1</code>, <code>IR2</code> <code>2</code>, and <code>IR3</code> <code>3</code>. I found that scikit-learn's <code>LabelEncoder</code> can do the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html" rel="nofollow noreferrer">job</a>, but there's a problem. Some of these categorical variables are implicitly ordinal, and <code>0</code>, <code>1</code>, ... need to be assigned to the right labels, and <code>LotShape</code> only happens to be in order there. </p>
  
  <p>So my question is, how would I efficiently, in some order that I specify, label a large number of categorical variables?</p>