title: How to change column values and sort with pandas?
body: <p>I have the following pandas DataFrame.</p>
  
  <pre><code>import pandas as pd
  df = pd.read_csv('filename.csv')
  
  print(df)
  
       cat      A         B           C
  0     cat1    0.787575  0.159330    0.053095
  1     cat10   0.770698  0.169487    0.059815
  2     cat11   0.792689  0.152043    0.055268
  3     cat12   0.785066  0.160361    0.054573
  4     cat13   0.795455  0.150464    0.054081
  5     cat14   0.794873  0.150700    0.054426
  ..    ....
  8     cat19   0.811585  0.140207    0.048208
  9     cat2    0.797202  0.152033    0.050765
  10    cat20   0.801607  0.145137    0.053256
  11    cat21   0.792689  0.152043    0.055268
      ....
  </code></pre>
  
  <p>Obviously, <code>cat1</code> is in the incorrect order, because <code>cat2</code> should go after <code>cat1</code>, not after <code>cat19</code>.</p>
  
  <p>What methods can one use to rectify this? </p>
  
  <p>My idea would be to relabel each single-digit <code>cat</code> and then sort with <code>.sort()</code>. However, my method for doing this doesn't work.</p>
  
  <pre><code>df = df.rename(index={'cat1': 'cat01'})
  df = df.rename(index={'cat2': 'cat02'})
  df = df.rename(index={'cat3': 'cat03'})
  ...
  df = df.rename(index={'cat9': 'cat09'})
  </code></pre>
  
  <p>It appears one has to change the index to the <code>cat</code> column, then use the above method, and sort. </p>
  
  <p>However, I am still typing out far too much. What is the best way to accomplish this? </p>