title: Pandas dataframe encode Categorical variable with thousands of unique values
body: <p>I have a dataframe about data on schools for a few thousands cities. The school is the row identifier and the city is encoded as follow:</p>
  
  <pre><code>school city          category   capacity
  1      azez6576sebd  45         23
  2      dsqozbc765aj  12         236
  3      sqdqsd12887s  8          63 
  4      azez6576sebd  7          234 
  ...
  </code></pre>
  
  <p>How can I convert the city variable to numeric knowing that I have a few thousand cities ? I guess one-hot encoding is not appropriate as I will have too many columns. What is the general approach to convert categorical variable with thousand of levels to numeric ?</p>
  
  <p>Thank you.</p>